Skip to content

Commit dec4d30

Browse files
committed
M3-2-1: Exclude member variables
Exclude member variables and variables from templates or template instantiations, as the rule is only applicable to objects.
1 parent 53c7483 commit dec4d30

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

cpp/autosar/src/rules/M3-2-1/DeclarationsOfAnObjectShallHaveCompatibleTypes.ql

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ import cpp
2020
import codingstandards.cpp.autosar
2121
import codingstandards.cpp.Typehelpers
2222

23+
predicate isNonTemplateObjectVariable(GlobalOrNamespaceVariable gv) {
24+
not gv.isFromTemplateInstantiation(_) and
25+
not gv.isFromUninstantiatedTemplate(_)
26+
}
27+
2328
from VariableDeclarationEntry decl1, VariableDeclarationEntry decl2
2429
where
2530
not isExcluded(decl1, DeclarationsPackage::declarationsOfAnObjectShallHaveCompatibleTypesQuery()) and
@@ -28,16 +33,9 @@ where
2833
// Note that normally `VariableDeclarationEntry` includes parameters, which are not covered
2934
// by this query. We implicitly exclude them with the `getQualifiedName()` predicate.
3035
decl1.getVariable().getQualifiedName() = decl2.getVariable().getQualifiedName() and
31-
// The underlying Variable shouldn't be from a TemplateVariable or a template instantiation
32-
not exists(Variable v |
33-
v = decl1.getVariable()
34-
or
35-
v = decl2.getVariable()
36-
|
37-
v instanceof TemplateVariable
38-
or
39-
v.isFromTemplateInstantiation(_)
40-
)
36+
// Only consider global/namespace variables which aren't templated
37+
isNonTemplateObjectVariable(decl1.getVariable()) and
38+
isNonTemplateObjectVariable(decl2.getVariable())
4139
select decl1,
4240
"The object $@ of type " + decl1.getType().toString() +
4341
" is not compatible with re-declaration $@ of type " + decl2.getType().toString(), decl1,

0 commit comments

Comments
 (0)