-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathUnscopedEnumerationsShouldNotBeDeclared.ql
More file actions
35 lines (32 loc) · 1.23 KB
/
UnscopedEnumerationsShouldNotBeDeclared.ql
File metadata and controls
35 lines (32 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* @id cpp/misra/unscoped-enumerations-should-not-be-declared
* @name RULE-10-2-2: Unscoped enumerations should not be declared
* @description An unscoped enumeration should not be used outside of a class/struct scope; use
* 'enum class' instead to prevent name clashes and implicit conversions to integral
* types.
* @kind problem
* @precision very-high
* @problem.severity warning
* @tags external/misra/id/rule-10-2-2
* scope/single-translation-unit
* correctness
* maintainability
* external/misra/enforcement/decidable
* external/misra/obligation/advisory
*/
import cpp
import codingstandards.cpp.misra
class NestedUnscopedEnum extends Enum, NestedEnum {
NestedUnscopedEnum() { not this instanceof ScopedEnum }
}
from Enum enum, string message
where
not isExcluded(enum, Banned2Package::unscopedEnumerationsShouldNotBeDeclaredQuery()) and
not (enum instanceof ScopedEnum or enum instanceof NestedUnscopedEnum) and
(
if enum.isAnonymous()
then message = "Unnamed enumeration is unscoped and not enclosed in a class or a struct."
else
message = "Enum " + enum.getName() + " is unscoped and not enclosed in a class or a struct."
)
select enum, message