Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
850a1d5
Fix regex for octal literal matching
mbaluda May 19, 2026
f484080
Exclude user-defined literals and templates
mbaluda May 21, 2026
2b15b72
add release notes
mbaluda May 21, 2026
e02b355
Potential fix for pull request finding
mbaluda May 21, 2026
acc2856
Potential fix for pull request finding
mbaluda May 21, 2026
aae7003
Use codingstandards.cpp.UserDefinedLiteral
mbaluda May 21, 2026
afe84b4
Update change_notes/2026-05-21-fix-fp-rule-5-13-4.md
mbaluda Jun 2, 2026
c9e3684
Merge branch 'main' into mbaluda-patch-1
mbaluda Jun 2, 2026
4d89b43
Update test.cpp
mbaluda Jun 2, 2026
767faec
Introduce support for agentic autofix
mbaluda May 26, 2026
eac0acd
Refactor NumericLiteral and UserDefinedLiteral classes for improved c…
mbaluda Jun 2, 2026
44bd9f1
Exclude user-defined literals from NumericLiteral constructor
mbaluda Jun 2, 2026
ffa1980
Update UserDefinedLiteral imports to use UserDefinedLiteralDeclaratio…
mbaluda Jun 2, 2026
b40dd32
Remove Agentic Autofix reference from user manual
mbaluda Jun 2, 2026
f6da148
Delete docs/copilot-instructions.md
mbaluda Jun 2, 2026
7c45bff
Update 2026-05-21-fix-fp-rule-5-13-4.md
mbaluda Jun 2, 2026
d6f19cd
Update import statement for UserDefinedLiteral to use UserDefinedLite…
mbaluda Jun 2, 2026
607d681
Merge branch 'main' into mbaluda-patch-1
mbaluda Jun 2, 2026
66b653b
Add documentation for user defined literal operator and usage
mbaluda Jun 3, 2026
831386d
Fix formatting in UserDefinedLiteral.qll documentation
mbaluda Jun 3, 2026
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
5 changes: 5 additions & 0 deletions change_notes/2026-05-21-fix-fp-rule-5-13-4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- `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.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import cpp
import codingstandards.cpp.autosar
import codingstandards.cpp.UserDefinedLiteral as udl

from udl::UserDefinedLiteral udl
from udl::UserDefinedLiteralDeclaration udl
where
not isExcluded(udl, NamingPackage::userDefinedLiteralOperatorSuffixViolationQuery()) and
not udl.hasCompliantSuffix()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import codingstandards.cpp.UserDefinedLiteral as udl
import codingstandards.cpp.SideEffect
import codingstandards.cpp.sideeffect.DefaultEffects

from udl::UserDefinedLiteral udl, SideEffect e
from udl::UserDefinedLiteralDeclaration udl, SideEffect e
where
not isExcluded(udl,
SideEffects2Package::userDefinedLiteralsOperatorsShallNotHaveSideEffectsQuery()) and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import codingstandards.cpp.autosar
import codingstandards.cpp.UserDefinedLiteral as udl
import codingstandards.cpp.SideEffect

from udl::UserDefinedLiteral udl, Expr retExpr
from udl::UserDefinedLiteralDeclaration udl, Expr retExpr
where
not isExcluded(udl,
SideEffects2Package::userDefinedLiteralsOperatorsShallOnlyPerformConversionOfPassedParametersQuery()) and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import cpp
import codingstandards.cpp.cert
import codingstandards.cpp.UserDefinedLiteral as udl

from udl::UserDefinedLiteral udl
from udl::UserDefinedLiteralDeclaration udl
where
not isExcluded(udl, NamingPackage::useOfReservedLiteralSuffixIdentifierQuery()) and
not udl.hasCompliantSuffix()
Expand Down
8 changes: 7 additions & 1 deletion cpp/common/src/codingstandards/cpp/Cpp14Literal.qll
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
*/
module Cpp14Literal {
private import cpp as StandardLibrary
private import codingstandards.cpp.UserDefinedLiteral

/** 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 this instanceof UserDefinedLiteral
}
Comment thread
mbaluda marked this conversation as resolved.
}

/** Convenience for implementing class `UnrecognizedNumericLiteral` */
abstract private class RecognizedNumericLiteral extends StandardLibrary::Literal { }
Expand Down
28 changes: 26 additions & 2 deletions cpp/common/src/codingstandards/cpp/UserDefinedLiteral.qll
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@

import cpp

class UserDefinedLiteral extends Function {
UserDefinedLiteral() {
/**
* A user defined literal operator is a function that defines the behavior of a user defined literal.
* It is declared using the `operator ""` syntax.
* ```
* constexpr long operator""_km(unsigned long value) {
* ...
* }
* ```
*/
class UserDefinedLiteralDeclaration extends Function {
UserDefinedLiteralDeclaration() {
// We use the '?' in this regexp because CodeQL CLI 2.4.6 and earlier reported these operators
// using a single ", i.e `operator "`. This has been fixed in 2.5.9 (at the latest), but I
// don't know if upgraded older databases will still have the broken version in. I've therefore
Comment thread
mbaluda marked this conversation as resolved.
Expand All @@ -16,3 +25,18 @@ class UserDefinedLiteral extends Function {
/** Holds if `this` has a compliant suffix. */
predicate hasCompliantSuffix() { this.getName().regexpMatch("operator \"\"?_\\p{Alpha}+") }
}

/**
* A user defined literal is a literal that is passed as an argument to a call to a user defined literal operator.
* ```
* 1000_km;
* ```
*/
class UserDefinedLiteral extends Literal {
UserDefinedLiteral() {
exists(FunctionCall fc |
this = fc.getArgument(0) and
fc.getTarget() instanceof UserDefinedLiteralDeclaration
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ query predicate problems(Cpp14Literal::NumericLiteral nl, string message) {
nl.getType().getUnspecifiedType().(IntegralType).isUnsigned() and
// The literal already has a `u` or `U` suffix.
not nl.getValueText().regexpMatch(".*[lL]*[uU][lL]*") and
// exclude literals derived from template instantiations
not nl.isFromTemplateInstantiation(_) and
message = literalKind + " literal is an unsigned integer but does not include a 'U' suffix."
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,20 @@ void test_macro() {
COMPLIANT_VAL; // COMPLIANT
NON_COMPLIANT_VAL; // NON_COMPLIANT[FALSE_NEGATIVE] - cannot determine suffix
// in macro expansions
}
}

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 <typename T> unsigned long long instantiated_literal_exclusion() {
return T{}; // COMPLIANT - template instantiation should be excluded
}

void test_instantiated_literal_exclusion() {
instantiated_literal_exclusion<int>();
}
Comment on lines +556 to +562
Loading