From 850a1d52013c3f0099072899ca51a6587dac6b76 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Tue, 19 May 2026 23:49:29 +0200 Subject: [PATCH 1/6] 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 2/6] 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 3/6] 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 4/6] 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 5/6] 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 6/6] 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(_)