Skip to content

Commit 6aa9c90

Browse files
committed
M3-2-1: Exclude TemplateVariable decls and decls in instantiations
TemplateVariables and variables in template instantiations are excluded because they cause spurious results for this query.
1 parent 79fc3a9 commit 6aa9c90

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ where
2727
not areCompatible(decl1.getType(), decl2.getType()) and
2828
// Note that normally `VariableDeclarationEntry` includes parameters, which are not covered
2929
// by this query. We implicitly exclude them with the `getQualifiedName()` predicate.
30-
decl1.getVariable().getQualifiedName() = decl2.getVariable().getQualifiedName()
30+
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+
)
3141
select decl1, "The object $@ is not compatible with re-declaration $@", decl1, decl1.getName(),
3242
decl2, decl2.getName()

cpp/autosar/test/rules/M3-2-1/DeclarationsOfAnObjectShallHaveCompatibleTypes.expected

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
| test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:7:5:7:6 | definition of a7 | The object $@ is not compatible with re-declaration $@ | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:7:5:7:6 | definition of a7 | a7 | test_declarations_of_an_object_shall_have_compatible_types_unit2.cpp:19:11:19:12 | declaration of a7 | a7 |
55
| test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:14:5:14:6 | definition of a2 | The object $@ is not compatible with re-declaration $@ | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:14:5:14:6 | definition of a2 | a2 | test_declarations_of_an_object_shall_have_compatible_types_unit2.cpp:23:13:23:14 | declaration of a2 | a2 |
66
| test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:19:5:19:7 | definition of a11 | The object $@ is not compatible with re-declaration $@ | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:19:5:19:7 | definition of a11 | a11 | test_declarations_of_an_object_shall_have_compatible_types_unit2.cpp:28:12:28:14 | declaration of a11 | a11 |
7-
| test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:32:22:32 | definition of number_one | The object $@ is not compatible with re-declaration $@ | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:32:22:32 | definition of number_one | number_one | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:32:22:32 | definition of number_one | number_one |
8-
| test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:32:22:32 | definition of number_one | The object $@ is not compatible with re-declaration $@ | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:32:22:32 | definition of number_one | number_one | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:32:22:32 | definition of number_one | number_one |
9-
| test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:32:22:32 | definition of number_one | The object $@ is not compatible with re-declaration $@ | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:32:22:32 | definition of number_one | number_one | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:43:22:43 | definition of number_one | number_one |
10-
| test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:32:22:32 | definition of number_one | The object $@ is not compatible with re-declaration $@ | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:32:22:32 | definition of number_one | number_one | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:43:22:43 | definition of number_one | number_one |
11-
| test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:43:22:43 | definition of number_one | The object $@ is not compatible with re-declaration $@ | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:43:22:43 | definition of number_one | number_one | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:32:22:32 | definition of number_one | number_one |
12-
| test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:43:22:43 | definition of number_one | The object $@ is not compatible with re-declaration $@ | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:43:22:43 | definition of number_one | number_one | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:22:32:22:32 | definition of number_one | number_one |
137
| test_declarations_of_an_object_shall_have_compatible_types_unit2.cpp:11:12:11:13 | declaration of a4 | The object $@ is not compatible with re-declaration $@ | test_declarations_of_an_object_shall_have_compatible_types_unit2.cpp:11:12:11:13 | declaration of a4 | a4 | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:4:6:4:7 | definition of a4 | a4 |
148
| test_declarations_of_an_object_shall_have_compatible_types_unit2.cpp:13:13:13:14 | declaration of a5 | The object $@ is not compatible with re-declaration $@ | test_declarations_of_an_object_shall_have_compatible_types_unit2.cpp:13:13:13:14 | declaration of a5 | a5 | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:5:5:5:6 | definition of a5 | a5 |
159
| test_declarations_of_an_object_shall_have_compatible_types_unit2.cpp:17:1:17:3 | declaration of a6 | The object $@ is not compatible with re-declaration $@ | test_declarations_of_an_object_shall_have_compatible_types_unit2.cpp:17:1:17:3 | declaration of a6 | a6 | test_declarations_of_an_object_shall_have_compatible_types_unit1.cpp:6:6:6:7 | definition of a6 | a6 |

0 commit comments

Comments
 (0)