Skip to content

Commit a4ca321

Browse files
authored
Merge pull request #394 from github/lcartey/m8-5-2-aggregate-variadic
`M8-5-2`: recognise aggregate literals initialized with parameters from variadic templates.
2 parents 833aeb2 + abdd0cd commit a4ca321

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`M8-5-2` - `AggregateLiteralEnhancements.qll`:
2+
- recognise aggregate literals initialized with parameters from variadic templates.

cpp/autosar/test/rules/M8-5-2/test.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,13 @@ void test() {
5555
Bar b2{{0}}; // NON_COMPLIANT - missing explicit init, nested zero init
5656
StructNested n{}; // COMPLIANT
5757
StructNested n1 = {}; // COMPLIANT
58-
}
58+
}
59+
60+
#include <initializer_list>
61+
template <class T> bool all_of(std::initializer_list<T>);
62+
63+
template <typename... Args> constexpr bool all_of(Args... args) noexcept {
64+
return all_of({args...}); // COMPLIANT - explicitly initialized via varargs
65+
}
66+
67+
void test_all_of() { all_of(true, false, false); }

cpp/common/src/codingstandards/cpp/enhancements/AggregateLiteralEnhancements.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ module ArrayAggregateLiterals {
8585
// The aggregate itself not be compiler generated, or in a macro expansion, otherwise our line numbers will be off
8686
not cal.isCompilerGenerated() and
8787
not cal.isInMacroExpansion() and
88+
// Ignore cases where the compilerGenerated value is a variable access targeting
89+
// a parameter, as these are generated from variadic templates
90+
not compilerGeneratedVal.(VariableAccess).getTarget() instanceof Parameter and
8891
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
8992
compilerGeneratedVal.getLocation().hasLocationInfo(filepath, _, _, endline, endcolumn) and
9093
previousExpr

0 commit comments

Comments
 (0)