From 5efac9768a4edd9f36775c37c5f5f732f9822da0 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Wed, 4 Oct 2023 23:09:24 +0100 Subject: [PATCH 1/3] M8-5-2: recognise aggregate literals initialized with parameters from variadic templates. --- ...0-04-aggregate-literals-from-variadic-templates.md | 1 + cpp/autosar/test/rules/M8-5-2/test.cpp | 11 ++++++++++- .../cpp/enhancements/AggregateLiteralEnhancements.qll | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 change_notes/2023-10-04-aggregate-literals-from-variadic-templates.md diff --git a/change_notes/2023-10-04-aggregate-literals-from-variadic-templates.md b/change_notes/2023-10-04-aggregate-literals-from-variadic-templates.md new file mode 100644 index 0000000000..f282d92565 --- /dev/null +++ b/change_notes/2023-10-04-aggregate-literals-from-variadic-templates.md @@ -0,0 +1 @@ + * `M8-5-2` - recognise aggregate literals initialized with parameters from variadic templates. \ No newline at end of file diff --git a/cpp/autosar/test/rules/M8-5-2/test.cpp b/cpp/autosar/test/rules/M8-5-2/test.cpp index b3a75e92ee..d78dd3df81 100644 --- a/cpp/autosar/test/rules/M8-5-2/test.cpp +++ b/cpp/autosar/test/rules/M8-5-2/test.cpp @@ -55,4 +55,13 @@ void test() { Bar b2{{0}}; // NON_COMPLIANT - missing explicit init, nested zero init StructNested n{}; // COMPLIANT StructNested n1 = {}; // COMPLIANT -} \ No newline at end of file +} + +#include +template bool all_of(std::initializer_list); + +template constexpr bool all_of(Args... args) noexcept { + return all_of({args...}); +} + +void test_all_of() { all_of(true, false, false); } \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/enhancements/AggregateLiteralEnhancements.qll b/cpp/common/src/codingstandards/cpp/enhancements/AggregateLiteralEnhancements.qll index 4d80fc16a2..34f91cf611 100644 --- a/cpp/common/src/codingstandards/cpp/enhancements/AggregateLiteralEnhancements.qll +++ b/cpp/common/src/codingstandards/cpp/enhancements/AggregateLiteralEnhancements.qll @@ -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 From d3b3e42540b5c22d3324308d66f5f970e2fc7174 Mon Sep 17 00:00:00 2001 From: Luke Cartey <5377966+lcartey@users.noreply.github.com> Date: Wed, 14 Feb 2024 23:44:24 +0000 Subject: [PATCH 2/3] Update change_notes/2023-10-04-aggregate-literals-from-variadic-templates.md Co-authored-by: Remco Vermeulen --- .../2023-10-04-aggregate-literals-from-variadic-templates.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/change_notes/2023-10-04-aggregate-literals-from-variadic-templates.md b/change_notes/2023-10-04-aggregate-literals-from-variadic-templates.md index f282d92565..7d5c36df93 100644 --- a/change_notes/2023-10-04-aggregate-literals-from-variadic-templates.md +++ b/change_notes/2023-10-04-aggregate-literals-from-variadic-templates.md @@ -1 +1,2 @@ - * `M8-5-2` - recognise aggregate literals initialized with parameters from variadic templates. \ No newline at end of file + `M8-5-2` - `AggregateLiteralEnhancements.qll`: + - recognise aggregate literals initialized with parameters from variadic templates. \ No newline at end of file From 002fc4a3091524b882fa782c4ce5965803bcc0e6 Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Wed, 21 Feb 2024 22:51:57 +0000 Subject: [PATCH 3/3] Add COMPLIANT marker --- cpp/autosar/test/rules/M8-5-2/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/autosar/test/rules/M8-5-2/test.cpp b/cpp/autosar/test/rules/M8-5-2/test.cpp index d78dd3df81..9c5efb726d 100644 --- a/cpp/autosar/test/rules/M8-5-2/test.cpp +++ b/cpp/autosar/test/rules/M8-5-2/test.cpp @@ -61,7 +61,7 @@ void test() { template bool all_of(std::initializer_list); template constexpr bool all_of(Args... args) noexcept { - return all_of({args...}); + return all_of({args...}); // COMPLIANT - explicitly initialized via varargs } void test_all_of() { all_of(true, false, false); } \ No newline at end of file