Skip to content
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 @@
- `RULE-5-13-4`, `M2-13-3` - `UnsignedIntegerLiteralsNotAppropriatelySuffixed.ql`, `MissingUSuffix.ql`:
- Remove false positives for literals in macro expansions (e.g. `0U`), as the suffix information is lost in this case. This is consistent with `RULE-7-2`.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ 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 generated by macro expansions, because the suffix information is lost in
// this case, so can cause false positives.
not nl.isInMacroExpansion() 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."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,11 @@ template <typename T> unsigned long long instantiated_literal_exclusion() {
void test_instantiated_literal_exclusion() {
instantiated_literal_exclusion<int>();
}

#define TEST_MACRO(value) (value)

void test_literals_in_macro_argument() {
TEST_MACRO(1U == 0U); // COMPLIANT
TEST_MACRO(020000000000); // NON_COMPLIANT[FALSE_NEGATIVE] - cannot determine
// suffix in macro expansions
}
Loading