Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M8-5-2: recognise aggregate literals initialized with parameters from variadic templates. #394

Merged
merged 6 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`M8-5-2` - `AggregateLiteralEnhancements.qll`:
- recognise aggregate literals initialized with parameters from variadic templates.
11 changes: 10 additions & 1 deletion cpp/autosar/test/rules/M8-5-2/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,13 @@ void test() {
Bar b2{{0}}; // NON_COMPLIANT - missing explicit init, nested zero init
StructNested n{}; // COMPLIANT
StructNested n1 = {}; // COMPLIANT
}
}

#include <initializer_list>
template <class T> bool all_of(std::initializer_list<T>);

template <typename... Args> constexpr bool all_of(Args... args) noexcept {
return all_of({args...}); // COMPLIANT - explicitly initialized via varargs
}

void test_all_of() { all_of(true, false, false); }
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ module ArrayAggregateLiterals {
// The aggregate itself not be compiler generated, or in a macro expansion, otherwise our line numbers will be off
not cal.isCompilerGenerated() and
not cal.isInMacroExpansion() and
// Ignore cases where the compilerGenerated value is a variable access targeting
// a parameter, as these are generated from variadic templates
not compilerGeneratedVal.(VariableAccess).getTarget() instanceof Parameter and
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
compilerGeneratedVal.getLocation().hasLocationInfo(filepath, _, _, endline, endcolumn) and
previousExpr
Expand Down
Loading