From 850a1d52013c3f0099072899ca51a6587dac6b76 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Tue, 19 May 2026 23:49:29 +0200 Subject: [PATCH 01/13] Fix regex for octal literal matching --- cpp/common/src/codingstandards/cpp/Cpp14Literal.qll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll b/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll index 8e0c089f4d..12f10eaf3d 100644 --- a/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll +++ b/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll @@ -49,7 +49,7 @@ module Cpp14Literal { * Octal literals must always start with the digit `0`. */ class OctalLiteral extends IntegerLiteral, RecognizedNumericLiteral { - OctalLiteral() { getValueText().regexpMatch("\\s*0[0-7']*[uUlL]*\\s*") } + OctalLiteral() { getValueText().regexpMatch("\\s*0[0-7']+[uUlL]*\\s*") } override string getAPrimaryQlClass() { result = "OctalLiteral" } } From f484080053e2bbf377476076f5a4b9ef20f0a8b4 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Thu, 21 May 2026 14:38:26 +0200 Subject: [PATCH 02/13] Exclude user-defined literals and templates --- cpp/common/src/codingstandards/cpp/Cpp14Literal.qll | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll b/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll index 12f10eaf3d..588d16ba6c 100644 --- a/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll +++ b/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll @@ -7,7 +7,16 @@ module Cpp14Literal { private import cpp as StandardLibrary /** An numeric literal. */ - abstract class NumericLiteral extends StandardLibrary::Literal { } + abstract class NumericLiteral extends StandardLibrary::Literal { + NumericLiteral() { + // exclude user-defined literals as they define custom suffixes + not exists(StandardLibrary::FunctionCall fc | + this = fc.getArgument(0) and fc.getTarget().getName().matches("operator \"\"%") + ) and + // exclude literals derived from template instantiations + not this.isFromTemplateInstantiation(_) + } + } /** Convenience for implementing class `UnrecognizedNumericLiteral` */ abstract private class RecognizedNumericLiteral extends StandardLibrary::Literal { } @@ -49,7 +58,7 @@ module Cpp14Literal { * Octal literals must always start with the digit `0`. */ class OctalLiteral extends IntegerLiteral, RecognizedNumericLiteral { - OctalLiteral() { getValueText().regexpMatch("\\s*0[0-7']+[uUlL]*\\s*") } + OctalLiteral() { getValueText().regexpMatch("\\s*0[0-7']*[uUlL]*\\s*") } override string getAPrimaryQlClass() { result = "OctalLiteral" } } From 2b15b72b826555ceb30fb553126cd146b50d3765 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Thu, 21 May 2026 14:49:04 +0200 Subject: [PATCH 03/13] add release notes --- change_notes/2026-05-21-fix-fp-rule-5-13-4.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 change_notes/2026-05-21-fix-fp-rule-5-13-4.md diff --git a/change_notes/2026-05-21-fix-fp-rule-5-13-4.md b/change_notes/2026-05-21-fix-fp-rule-5-13-4.md new file mode 100644 index 0000000000..71faf5337b --- /dev/null +++ b/change_notes/2026-05-21-fix-fp-rule-5-13-4.md @@ -0,0 +1,5 @@ +- `RULE-5-13-4` - `cpp/misra/unsigned-integer-literals-not-appropriately-suffixed`: + - Remove FPs in user-defined literals and tamplate instantiations. +- `M2-13-3` - `cpp/autosar/missing-u-suffix`: + - Remove FPs in user-defined literals and tamplate instantiations. + \ No newline at end of file From e02b35532a648e6ab6f3c35e89f535e04c4dd4e2 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Thu, 21 May 2026 15:17:12 +0200 Subject: [PATCH 04/13] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- change_notes/2026-05-21-fix-fp-rule-5-13-4.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/change_notes/2026-05-21-fix-fp-rule-5-13-4.md b/change_notes/2026-05-21-fix-fp-rule-5-13-4.md index 71faf5337b..854135aae2 100644 --- a/change_notes/2026-05-21-fix-fp-rule-5-13-4.md +++ b/change_notes/2026-05-21-fix-fp-rule-5-13-4.md @@ -1,5 +1,5 @@ - `RULE-5-13-4` - `cpp/misra/unsigned-integer-literals-not-appropriately-suffixed`: - - Remove FPs in user-defined literals and tamplate instantiations. + - Remove FPs in user-defined literals and template instantiations. - `M2-13-3` - `cpp/autosar/missing-u-suffix`: - - Remove FPs in user-defined literals and tamplate instantiations. + - Remove FPs in user-defined literals and template instantiations. \ No newline at end of file From acc2856e9009fc50ee809a5312365f93a4ced54c Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Thu, 21 May 2026 15:18:34 +0200 Subject: [PATCH 05/13] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- cpp/common/src/codingstandards/cpp/Cpp14Literal.qll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll b/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll index 588d16ba6c..f95337fdf2 100644 --- a/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll +++ b/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll @@ -6,7 +6,7 @@ module Cpp14Literal { private import cpp as StandardLibrary - /** An numeric literal. */ + /** A numeric literal. */ abstract class NumericLiteral extends StandardLibrary::Literal { NumericLiteral() { // exclude user-defined literals as they define custom suffixes From aae700337a6adc7c030120d995021b83ba954882 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Thu, 21 May 2026 17:11:18 +0200 Subject: [PATCH 06/13] Use codingstandards.cpp.UserDefinedLiteral --- cpp/common/src/codingstandards/cpp/Cpp14Literal.qll | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll b/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll index f95337fdf2..1bd815eba5 100644 --- a/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll +++ b/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll @@ -5,13 +5,15 @@ */ module Cpp14Literal { private import cpp as StandardLibrary + private import codingstandards.cpp.UserDefinedLiteral - /** A numeric literal. */ + /** An numeric literal. */ abstract class NumericLiteral extends StandardLibrary::Literal { NumericLiteral() { // exclude user-defined literals as they define custom suffixes not exists(StandardLibrary::FunctionCall fc | - this = fc.getArgument(0) and fc.getTarget().getName().matches("operator \"\"%") + this = fc.getArgument(0) and + fc.getTarget() instanceof UserDefinedLiteral ) and // exclude literals derived from template instantiations not this.isFromTemplateInstantiation(_) From afe84b4a77afead5492c6cb381fb5ea4bcdbc219 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Tue, 2 Jun 2026 19:30:21 +0200 Subject: [PATCH 07/13] Update change_notes/2026-05-21-fix-fp-rule-5-13-4.md Co-authored-by: Michael R Fairhurst --- change_notes/2026-05-21-fix-fp-rule-5-13-4.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change_notes/2026-05-21-fix-fp-rule-5-13-4.md b/change_notes/2026-05-21-fix-fp-rule-5-13-4.md index 854135aae2..5d1ae57c22 100644 --- a/change_notes/2026-05-21-fix-fp-rule-5-13-4.md +++ b/change_notes/2026-05-21-fix-fp-rule-5-13-4.md @@ -1,4 +1,4 @@ -- `RULE-5-13-4` - `cpp/misra/unsigned-integer-literals-not-appropriately-suffixed`: +- `RULE-5-13-4`, `M2-13-3` - `UnsignedIntegerLiteralsNotAppropriatelSuffixed.ql`, `MissingUSuffix.ql`: - Remove FPs in user-defined literals and template instantiations. - `M2-13-3` - `cpp/autosar/missing-u-suffix`: - Remove FPs in user-defined literals and template instantiations. From 742ef1691427345431feb020c6cade674593bd9b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Jun 2026 17:32:31 +0000 Subject: [PATCH 08/13] Initial plan From d783d8e257c48c48d6ccfa33fa77187a209ab852 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Jun 2026 17:36:10 +0000 Subject: [PATCH 09/13] Add test coverage for literal exclusion cases --- ...rLiteralsNotAppropriatelySuffixed.expected | 36 +++++++++---------- .../test.cpp | 15 ++++++++ 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/UnsignedIntegerLiteralsNotAppropriatelySuffixed.expected b/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/UnsignedIntegerLiteralsNotAppropriatelySuffixed.expected index 3326ede548..643c4672a6 100644 --- a/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/UnsignedIntegerLiteralsNotAppropriatelySuffixed.expected +++ b/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/UnsignedIntegerLiteralsNotAppropriatelySuffixed.expected @@ -1,18 +1,18 @@ -| test.cpp:111:3:111:12 | 2147483648 | Hex literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:116:3:116:20 | 9223372036854775808 | Hex literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:139:3:139:21 | 9223372036854775808 | Hex literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:162:3:162:21 | 9223372036854775808 | Hex literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:185:3:185:22 | 9223372036854775808 | Hex literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:208:3:208:22 | 9223372036854775808 | Hex literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:227:3:227:14 | 2147483648 | Octal literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:232:3:232:25 | 9223372036854775808 | Octal literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:249:3:249:26 | 9223372036854775808 | Octal literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:266:3:266:26 | 9223372036854775808 | Octal literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:283:3:283:27 | 9223372036854775808 | Octal literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:300:3:300:27 | 9223372036854775808 | Octal literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:315:3:315:36 | 2147483648 | Binary literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:322:3:322:68 | 9223372036854775808 | Binary literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:365:3:365:69 | 9223372036854775808 | Binary literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:412:3:412:69 | 9223372036854775808 | Binary literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:457:3:457:70 | 9223372036854775808 | Binary literal is an unsigned integer but does not include a 'U' suffix. | -| test.cpp:502:3:502:70 | 9223372036854775808 | Binary literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:126:3:126:12 | 2147483648 | Hex literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:131:3:131:20 | 9223372036854775808 | Hex literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:154:3:154:21 | 9223372036854775808 | Hex literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:177:3:177:21 | 9223372036854775808 | Hex literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:200:3:200:22 | 9223372036854775808 | Hex literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:223:3:223:22 | 9223372036854775808 | Hex literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:242:3:242:14 | 2147483648 | Octal literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:247:3:247:25 | 9223372036854775808 | Octal literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:264:3:264:26 | 9223372036854775808 | Octal literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:281:3:281:26 | 9223372036854775808 | Octal literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:298:3:298:27 | 9223372036854775808 | Octal literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:315:3:315:27 | 9223372036854775808 | Octal literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:330:3:330:36 | 2147483648 | Binary literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:337:3:337:68 | 9223372036854775808 | Binary literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:380:3:380:69 | 9223372036854775808 | Binary literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:427:3:427:69 | 9223372036854775808 | Binary literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:472:3:472:70 | 9223372036854775808 | Binary literal is an unsigned integer but does not include a 'U' suffix. | +| test.cpp:517:3:517:70 | 9223372036854775808 | Binary literal is an unsigned integer but does not include a 'U' suffix. | diff --git a/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/test.cpp b/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/test.cpp index fcbd51b3de..d76692ea49 100644 --- a/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/test.cpp +++ b/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/test.cpp @@ -105,6 +105,21 @@ void test_decimal_constants() { // than max long long int } +constexpr unsigned long long operator""_km(unsigned long long value) { + return value; +} + +void test_user_defined_literal_exclusion() { + 0x80000000_km; // COMPLIANT - user-defined literal argument should be excluded +} + +template +unsigned long long instantiated_literal_exclusion() { + return 0x80000000; // COMPLIANT - template instantiation should be excluded +} + +void instantiate_literal_exclusion() { (void)instantiated_literal_exclusion(); } + void test_hexadecimal_constants() { 0x0; // COMPLIANT - uses signed int 0x7FFFFFFF; // COMPLIANT - max value held by signed int From a165834b4e98a3e1c6a9b8d90c8d85aa91df9d76 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Jun 2026 17:36:49 +0000 Subject: [PATCH 10/13] Rename new template exclusion test for consistency --- .../unsignedintegerliteralsnotappropriatelysuffixed/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/test.cpp b/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/test.cpp index d76692ea49..12e1649e44 100644 --- a/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/test.cpp +++ b/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/test.cpp @@ -118,7 +118,7 @@ unsigned long long instantiated_literal_exclusion() { return 0x80000000; // COMPLIANT - template instantiation should be excluded } -void instantiate_literal_exclusion() { (void)instantiated_literal_exclusion(); } +void test_instantiated_literal_exclusion() { (void)instantiated_literal_exclusion(); } void test_hexadecimal_constants() { 0x0; // COMPLIANT - uses signed int From 97eaff9428f91af453e813415a8364ba07e70204 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Jun 2026 17:37:16 +0000 Subject: [PATCH 11/13] Simplify template exclusion test invocation --- .../unsignedintegerliteralsnotappropriatelysuffixed/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/test.cpp b/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/test.cpp index 12e1649e44..1a32ab9d1e 100644 --- a/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/test.cpp +++ b/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/test.cpp @@ -118,7 +118,7 @@ unsigned long long instantiated_literal_exclusion() { return 0x80000000; // COMPLIANT - template instantiation should be excluded } -void test_instantiated_literal_exclusion() { (void)instantiated_literal_exclusion(); } +void test_instantiated_literal_exclusion() { instantiated_literal_exclusion(); } void test_hexadecimal_constants() { 0x0; // COMPLIANT - uses signed int From 5c01928b5ea75a695b34c4281bff8ff74fdd01fe Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Tue, 2 Jun 2026 20:24:11 +0200 Subject: [PATCH 12/13] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- change_notes/2026-05-21-fix-fp-rule-5-13-4.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change_notes/2026-05-21-fix-fp-rule-5-13-4.md b/change_notes/2026-05-21-fix-fp-rule-5-13-4.md index 5d1ae57c22..3322c7db03 100644 --- a/change_notes/2026-05-21-fix-fp-rule-5-13-4.md +++ b/change_notes/2026-05-21-fix-fp-rule-5-13-4.md @@ -1,4 +1,4 @@ -- `RULE-5-13-4`, `M2-13-3` - `UnsignedIntegerLiteralsNotAppropriatelSuffixed.ql`, `MissingUSuffix.ql`: +- `RULE-5-13-4`, `M2-13-3` - `UnsignedIntegerLiteralsNotAppropriatelySuffixed.ql`, `MissingUSuffix.ql`: - Remove FPs in user-defined literals and template instantiations. - `M2-13-3` - `cpp/autosar/missing-u-suffix`: - Remove FPs in user-defined literals and template instantiations. From 796d6080362cd17e017fca2fb5e0eef48501fd73 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 2 Jun 2026 18:27:33 +0000 Subject: [PATCH 13/13] Fix QLDoc article in NumericLiteral comment --- cpp/common/src/codingstandards/cpp/Cpp14Literal.qll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll b/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll index 1bd815eba5..3cce767770 100644 --- a/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll +++ b/cpp/common/src/codingstandards/cpp/Cpp14Literal.qll @@ -7,7 +7,7 @@ module Cpp14Literal { private import cpp as StandardLibrary private import codingstandards.cpp.UserDefinedLiteral - /** An numeric literal. */ + /** A numeric literal. */ abstract class NumericLiteral extends StandardLibrary::Literal { NumericLiteral() { // exclude user-defined literals as they define custom suffixes