diff --git a/c/common/src/codingstandards/c/Extensions.qll b/c/common/src/codingstandards/c/Extensions.qll index 4f16a1f09a..dc2618d5ba 100644 --- a/c/common/src/codingstandards/c/Extensions.qll +++ b/c/common/src/codingstandards/c/Extensions.qll @@ -120,12 +120,7 @@ class CTerseTernaryExtension extends CCompilerExtension, ConditionalExpr { // Reference: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fint128.html#g_t_005f_005fint128 // Reference: https://gcc.gnu.org/onlinedocs/gcc/Decimal-Float.html#Decimal-Float class CRealTypeExtensionExtension extends CCompilerExtension, DeclarationEntry { - CRealTypeExtensionExtension() { - getType() instanceof Decimal128Type or - getType() instanceof Decimal32Type or - getType() instanceof Decimal64Type or - getType() instanceof Float128Type - } + CRealTypeExtensionExtension() { getType() instanceof Float128Type } override string getMessage() { result = "Decimal floats are a compiler extension and are not portable to other compilers." diff --git a/c/misra/test/rules/RULE-14-3/ControllingExprInvariant.expected b/c/misra/test/rules/RULE-14-3/ControllingExprInvariant.expected index 3beb834f84..c03c04d6cc 100644 --- a/c/misra/test/rules/RULE-14-3/ControllingExprInvariant.expected +++ b/c/misra/test/rules/RULE-14-3/ControllingExprInvariant.expected @@ -5,4 +5,3 @@ | test.c:27:10:27:14 | ... < ... | Controlling expression in loop statement has an invariant value. | | test.c:37:3:37:6 | 1 | Controlling expression in conditional statement has an invariant value. | | test.c:38:3:38:3 | 1 | Controlling expression in conditional statement has an invariant value. | -| test.c:45:10:45:26 | ... && ... | Controlling expression in loop statement has an invariant value. | diff --git a/c/misra/test/rules/RULE-14-3/test.c b/c/misra/test/rules/RULE-14-3/test.c index ed8854afd2..94b10d36b0 100644 --- a/c/misra/test/rules/RULE-14-3/test.c +++ b/c/misra/test/rules/RULE-14-3/test.c @@ -42,6 +42,6 @@ void f5(bool b1) { void f6(int p1) { while (p1 < 10 && p1 > 12) { // NON_COMPLIANT[FALSE_NEGATIVE] } - while (1 == 0 && p1 > 12) { // NON_COMPLIANT + while (1 == 0 && p1 > 12) { // NON_COMPLIANT[FALSE_NEGATIVE] } } \ No newline at end of file diff --git a/cpp/autosar/src/rules/A13-2-2/BinaryOperatorAndBitwiseOperatorReturnAPrvalue.ql b/cpp/autosar/src/rules/A13-2-2/BinaryOperatorAndBitwiseOperatorReturnAPrvalue.ql index c6c2e54378..8af33a43b2 100644 --- a/cpp/autosar/src/rules/A13-2-2/BinaryOperatorAndBitwiseOperatorReturnAPrvalue.ql +++ b/cpp/autosar/src/rules/A13-2-2/BinaryOperatorAndBitwiseOperatorReturnAPrvalue.ql @@ -17,7 +17,6 @@ import cpp import codingstandards.cpp.autosar import codingstandards.cpp.Operator -import semmle.code.cpp.Print from Operator o where diff --git a/cpp/autosar/src/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.ql b/cpp/autosar/src/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.ql index a8fb1ace66..5e0e88e1a3 100644 --- a/cpp/autosar/src/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.ql +++ b/cpp/autosar/src/rules/A14-5-2/NonTemplateMemberDefinedInTemplate.ql @@ -170,7 +170,7 @@ where ) and // Omit using alias (cf. https://github.com/github/codeql-coding-standards/issues/739) // Exclude Using alias which refer directly to a TypeParameter - not d.(UsingAliasTypedefType).getBaseType() instanceof TypeTemplateParameter + not d.(TypeAliasType).getBaseType() instanceof TypeTemplateParameter select d, "Member " + d.getName() + " template class does not use any of template arguments of its $@.", d.getDeclaringType(), "declaring type" diff --git a/cpp/autosar/src/rules/M3-2-3/MultipleDeclarationViolation.ql b/cpp/autosar/src/rules/M3-2-3/MultipleDeclarationViolation.ql index 30d94facb1..ce928f61ed 100644 --- a/cpp/autosar/src/rules/M3-2-3/MultipleDeclarationViolation.ql +++ b/cpp/autosar/src/rules/M3-2-3/MultipleDeclarationViolation.ql @@ -36,7 +36,7 @@ where kind = "variable" or de.getDeclaration() instanceof Type and - not de.getDeclaration() instanceof UsingAliasTypedefType and + not de.getDeclaration() instanceof TypeAliasType and kind = "type" ) and not otherDeclaration.isDefinition() and diff --git a/cpp/autosar/test/rules/A13-6-1/UseCorrectIntervalForDigitSequencesSeparators.expected b/cpp/autosar/test/rules/A13-6-1/UseCorrectIntervalForDigitSequencesSeparators.expected index 9cda0967bf..ee87fca749 100644 --- a/cpp/autosar/test/rules/A13-6-1/UseCorrectIntervalForDigitSequencesSeparators.expected +++ b/cpp/autosar/test/rules/A13-6-1/UseCorrectIntervalForDigitSequencesSeparators.expected @@ -7,8 +7,8 @@ | test.cpp:19:3:19:17 | 1370 | The digit sequence 01010101'1010 uses a digit sequence separator at a spacing other than 4. | | test.cpp:20:3:20:15 | 85 | The digit sequence 01'01'01'01 uses a digit sequence separator at a spacing other than 4. | | test.cpp:21:3:21:14 | 85 | The digit sequence 010'1010'1 uses a digit sequence separator at a spacing other than 4. | -| test.cpp:26:3:26:15 | 11000000000.0 | The digit sequence 1000'000 uses a digit sequence separator at a spacing other than 3. | -| test.cpp:27:3:27:16 | 11000000000.0 | The digit sequence 10'00'000 uses a digit sequence separator at a spacing other than 3. | -| test.cpp:28:3:28:17 | 11000000000.0 | The digit sequence 1'0 uses a digit sequence separator at a spacing other than 3. | -| test.cpp:29:3:29:16 | 11000000000.0 | The digit sequence 10'000'00 uses a digit sequence separator at a spacing other than 3. | -| test.cpp:30:3:30:15 | 11000000000.0 | The digit sequence 1'0 uses a digit sequence separator at a spacing other than 3. | +| test.cpp:26:3:26:15 | 1.1E10 | The digit sequence 1000'000 uses a digit sequence separator at a spacing other than 3. | +| test.cpp:27:3:27:16 | 1.1E10 | The digit sequence 10'00'000 uses a digit sequence separator at a spacing other than 3. | +| test.cpp:28:3:28:17 | 1.1E10 | The digit sequence 1'0 uses a digit sequence separator at a spacing other than 3. | +| test.cpp:29:3:29:16 | 1.1E10 | The digit sequence 10'000'00 uses a digit sequence separator at a spacing other than 3. | +| test.cpp:30:3:30:15 | 1.1E10 | The digit sequence 1'0 uses a digit sequence separator at a spacing other than 3. | diff --git a/cpp/autosar/test/rules/A2-10-5/IdentifierNameOfANonMemberObjectWithExternalOrInternalLinkageIsReused.expected b/cpp/autosar/test/rules/A2-10-5/IdentifierNameOfANonMemberObjectWithExternalOrInternalLinkageIsReused.expected index d6f496a3c6..b3284a9970 100644 --- a/cpp/autosar/test/rules/A2-10-5/IdentifierNameOfANonMemberObjectWithExternalOrInternalLinkageIsReused.expected +++ b/cpp/autosar/test/rules/A2-10-5/IdentifierNameOfANonMemberObjectWithExternalOrInternalLinkageIsReused.expected @@ -1,6 +1,6 @@ | test1a.cpp:2:12:2:13 | g1 | Identifier name of non-member object $@ reuses the identifier name of non-member object $@. | test1a.cpp:2:12:2:13 | g1 | g1 | test1b.cpp:2:12:2:13 | g1 | g1 | | test1a.cpp:6:12:6:13 | g3 | Identifier name of non-member object $@ reuses the identifier name of non-member object $@. | test1a.cpp:6:12:6:13 | g3 | g3 | test1b.cpp:6:12:6:13 | g3 | g3 | -| test1a.cpp:17:50:17:50 | number_two | Identifier name of non-member object $@ reuses the identifier name of non-member object $@. | test1a.cpp:17:50:17:50 | number_two | number_two | test1b.cpp:11:50:11:50 | number_two | number_two | +| test1a.cpp:17:39:17:48 | number_two | Identifier name of non-member object $@ reuses the identifier name of non-member object $@. | test1a.cpp:17:39:17:48 | number_two | number_two | test1b.cpp:11:39:11:48 | number_two | number_two | | test1b.cpp:2:12:2:13 | g1 | Identifier name of non-member object $@ reuses the identifier name of non-member object $@. | test1b.cpp:2:12:2:13 | g1 | g1 | test1a.cpp:2:12:2:13 | g1 | g1 | | test1b.cpp:6:12:6:13 | g3 | Identifier name of non-member object $@ reuses the identifier name of non-member object $@. | test1b.cpp:6:12:6:13 | g3 | g3 | test1a.cpp:6:12:6:13 | g3 | g3 | -| test1b.cpp:11:50:11:50 | number_two | Identifier name of non-member object $@ reuses the identifier name of non-member object $@. | test1b.cpp:11:50:11:50 | number_two | number_two | test1a.cpp:17:50:17:50 | number_two | number_two | +| test1b.cpp:11:39:11:48 | number_two | Identifier name of non-member object $@ reuses the identifier name of non-member object $@. | test1b.cpp:11:39:11:48 | number_two | number_two | test1a.cpp:17:39:17:48 | number_two | number_two | diff --git a/cpp/autosar/test/rules/M2-13-4/LiteralSuffixNotUpperCase.expected b/cpp/autosar/test/rules/M2-13-4/LiteralSuffixNotUpperCase.expected index 9397fbac49..66fa304117 100644 --- a/cpp/autosar/test/rules/M2-13-4/LiteralSuffixNotUpperCase.expected +++ b/cpp/autosar/test/rules/M2-13-4/LiteralSuffixNotUpperCase.expected @@ -8,5 +8,5 @@ | test.cpp:16:3:16:14 | 1254450 | Numeric literal 0x13'24'32Ul has the lower case suffix l. | | test.cpp:17:3:17:13 | 1254450 | Numeric literal 0x13'24'32u has the lower case suffix u. | | test.cpp:18:3:18:13 | 1254450 | Numeric literal 0x13'24'32l has the lower case suffix l. | -| test.cpp:22:3:22:15 | 1.123122995e+10 | Numeric literal 1.123'123e10f has the lower case suffix f. | -| test.cpp:23:3:23:15 | 11231230000.0 | Numeric literal 1.123'123e10l has the lower case suffix l. | +| test.cpp:22:3:22:15 | 1.123123E10 | Numeric literal 1.123'123e10f has the lower case suffix f. | +| test.cpp:23:3:23:15 | 1.123123E10 | Numeric literal 1.123'123e10l has the lower case suffix l. | diff --git a/cpp/autosar/test/rules/M5-0-6/ImplicitConstConversionToSmallerUnderlyingType.expected b/cpp/autosar/test/rules/M5-0-6/ImplicitConstConversionToSmallerUnderlyingType.expected index 6b1d701128..00e191758c 100644 --- a/cpp/autosar/test/rules/M5-0-6/ImplicitConstConversionToSmallerUnderlyingType.expected +++ b/cpp/autosar/test/rules/M5-0-6/ImplicitConstConversionToSmallerUnderlyingType.expected @@ -1,2 +1,2 @@ | test.cpp:11:8:11:10 | (int8_t)... | Implicit conversion of integral $@ reduces the size from 4 bytes to 1 bytes. | test.cpp:11:8:11:10 | 256 | 256 | -| test.cpp:24:9:24:14 | (float)... | Implicit conversion of floating point $@ reduces the size from 8 bytes to 4 bytes. | test.cpp:24:9:24:14 | 3.500000000000000016e+38 | 3.5e38 | +| test.cpp:24:9:24:14 | (float)... | Implicit conversion of floating point $@ reduces the size from 8 bytes to 4 bytes. | test.cpp:24:9:24:14 | 3.5E38 | 3.5e38 | diff --git a/cpp/common/src/codingstandards/cpp/Extensions.qll b/cpp/common/src/codingstandards/cpp/Extensions.qll index b085f89e5b..70cc34f69e 100644 --- a/cpp/common/src/codingstandards/cpp/Extensions.qll +++ b/cpp/common/src/codingstandards/cpp/Extensions.qll @@ -108,8 +108,8 @@ class CPPTerseTernaryExtension extends CPPCompilerExtension, ConditionalExpr { } /** - * A non-standard `Type` that is only available as a compiler extension, such as `__int128`, - * `_Decimal32`, `_Decimal64`, `_Decimal128`, or `__float128`. + * A non-standard `Type` that is only available as a compiler extension, such as `__int128` + * or `__float128`. * * Reference: https://gcc.gnu.org/onlinedocs/gcc/__int128.html * Reference: https://gcc.gnu.org/onlinedocs/gcc/Decimal-Float.html @@ -117,9 +117,6 @@ class CPPTerseTernaryExtension extends CPPCompilerExtension, ConditionalExpr { class CPPExtensionType extends Type { CPPExtensionType() { this instanceof Int128Type or - this instanceof Decimal128Type or - this instanceof Decimal32Type or - this instanceof Decimal64Type or this instanceof Float128Type } } diff --git a/cpp/common/src/codingstandards/cpp/Identifiers.qll b/cpp/common/src/codingstandards/cpp/Identifiers.qll index cbacb9b8e2..67fd8634b4 100644 --- a/cpp/common/src/codingstandards/cpp/Identifiers.qll +++ b/cpp/common/src/codingstandards/cpp/Identifiers.qll @@ -22,7 +22,7 @@ class InterestingIdentifiers extends Declaration { InterestingIdentifiers() { not this.isFromTemplateInstantiation(_) and not this.isFromUninstantiatedTemplate(_) and - not this instanceof TemplateParameter and + not this instanceof TypeTemplateParameter and not this.hasDeclaringType() and not this instanceof Operator and not this.hasName("main") and @@ -291,7 +291,7 @@ private module IdentifierIntroductionImpl { // A template parameter may itself be a template (`template class T>`). // The inner template parameter `template` is anonymous and does not introduce an // identifier. - not type.(TemplateParameter).isAnonymous() + not type.(TypeTemplateParameter).isAnonymous() or // In the above case, the template template parameter `T` is incorrectly marked as anonymous // in the database. But it does introduce the identifier `T`, so it must not be excluded. diff --git a/cpp/common/src/codingstandards/cpp/deadcode/UnusedVariables.qll b/cpp/common/src/codingstandards/cpp/deadcode/UnusedVariables.qll index a0caabe624..0e21cf6cc2 100644 --- a/cpp/common/src/codingstandards/cpp/deadcode/UnusedVariables.qll +++ b/cpp/common/src/codingstandards/cpp/deadcode/UnusedVariables.qll @@ -13,7 +13,7 @@ import codingstandards.cpp.Scope */ class TemplateDependentType extends Type { TemplateDependentType() { - this instanceof TemplateParameter + this instanceof TypeTemplateParameter or exists(TemplateDependentType t | this.refersToDirectly(t) and diff --git a/cpp/common/src/codingstandards/cpp/rules/multipleglobalormemberdeclarators/MultipleGlobalOrMemberDeclarators.qll b/cpp/common/src/codingstandards/cpp/rules/multipleglobalormemberdeclarators/MultipleGlobalOrMemberDeclarators.qll index 05821d7270..712e61ab03 100644 --- a/cpp/common/src/codingstandards/cpp/rules/multipleglobalormemberdeclarators/MultipleGlobalOrMemberDeclarators.qll +++ b/cpp/common/src/codingstandards/cpp/rules/multipleglobalormemberdeclarators/MultipleGlobalOrMemberDeclarators.qll @@ -31,7 +31,7 @@ Query getQuery() { result instanceof MultipleGlobalOrMemberDeclaratorsSharedQuer class NonLocalUserDeclaration extends Declaration { NonLocalUserDeclaration() { not this instanceof StackVariable and - not this instanceof TemplateParameter and + not this instanceof TypeTemplateParameter and not this instanceof EnumConstant and not this instanceof TypedefType and not any(LambdaCapture lc).getField() = this and diff --git a/cpp/common/src/codingstandards/cpp/rules/nonvoidfunctiondoesnotreturn/NonVoidFunctionDoesNotReturn.qll b/cpp/common/src/codingstandards/cpp/rules/nonvoidfunctiondoesnotreturn/NonVoidFunctionDoesNotReturn.qll index cd5d1bdef4..2ee0a1a152 100644 --- a/cpp/common/src/codingstandards/cpp/rules/nonvoidfunctiondoesnotreturn/NonVoidFunctionDoesNotReturn.qll +++ b/cpp/common/src/codingstandards/cpp/rules/nonvoidfunctiondoesnotreturn/NonVoidFunctionDoesNotReturn.qll @@ -16,7 +16,7 @@ predicate functionsMissingReturnStmt(Function f, ControlFlowNode blame) { exists(Type returnType | returnType = f.getUnspecifiedType() and not returnType instanceof VoidType and - not returnType instanceof TemplateParameter + not returnType instanceof TypeTemplateParameter ) and exists(ReturnStmt s | f.getAPredecessor() = s and diff --git a/cpp/common/src/codingstandards/cpp/rules/unnecessaryexposedidentifierdeclarationshared/UnnecessaryExposedIdentifierDeclarationShared.qll b/cpp/common/src/codingstandards/cpp/rules/unnecessaryexposedidentifierdeclarationshared/UnnecessaryExposedIdentifierDeclarationShared.qll index 695a8740b6..8b0dcbc6c2 100644 --- a/cpp/common/src/codingstandards/cpp/rules/unnecessaryexposedidentifierdeclarationshared/UnnecessaryExposedIdentifierDeclarationShared.qll +++ b/cpp/common/src/codingstandards/cpp/rules/unnecessaryexposedidentifierdeclarationshared/UnnecessaryExposedIdentifierDeclarationShared.qll @@ -218,7 +218,7 @@ class CandidateDeclaration extends Declaration { or this instanceof Type and not this instanceof ClassTemplateInstantiation and - not this instanceof TemplateParameter + not this instanceof TypeTemplateParameter } } diff --git a/cpp/common/src/codingstandards/cpp/rules/unusedtypedeclarations/UnusedTypeDeclarations.qll b/cpp/common/src/codingstandards/cpp/rules/unusedtypedeclarations/UnusedTypeDeclarations.qll index b6d085619a..a0de4fe329 100644 --- a/cpp/common/src/codingstandards/cpp/rules/unusedtypedeclarations/UnusedTypeDeclarations.qll +++ b/cpp/common/src/codingstandards/cpp/rules/unusedtypedeclarations/UnusedTypeDeclarations.qll @@ -14,7 +14,7 @@ Query getQuery() { result instanceof UnusedTypeDeclarationsSharedQuery } query predicate problems(UserType ut, string message) { not isExcluded(ut, getQuery()) and message = "Type declaration " + ut.getName() + " is not used." and - not ut instanceof TemplateParameter and + not ut instanceof TypeTemplateParameter and not ut instanceof ProxyClass and not exists(getATypeUse(ut)) and not ut.isFromUninstantiatedTemplate(_) diff --git a/cpp/common/src/codingstandards/cpp/types/Uses.qll b/cpp/common/src/codingstandards/cpp/types/Uses.qll index 3cd63f4bc7..cb70e5fa7d 100644 --- a/cpp/common/src/codingstandards/cpp/types/Uses.qll +++ b/cpp/common/src/codingstandards/cpp/types/Uses.qll @@ -98,7 +98,7 @@ private Locatable getATypeUse_i(Type type, string reason) { or // Unless it's an alias template instantiation, as they do not have correct locations (last // verified in CodeQL CLI 2.7.6) - result instanceof UsingAliasTypedefType and + result instanceof TypeAliasType and not exists(result.getLocation()) ) and ( @@ -203,7 +203,7 @@ private Locatable getATypeUse_i(Type type, string reason) { // Alias templates - alias templates and instantiations are not properly captured by the // extractor (last verified in CodeQL CLI 2.7.6). The only distinguishing factor is that // instantiations of alias templates do not have a location. - exists(UsingAliasTypedefType template, UsingAliasTypedefType instantiation | + exists(TypeAliasType template, TypeAliasType instantiation | // Instantiation is a "use" of the template used = instantiation and type = template and diff --git a/cpp/common/test/library/codingstandards/cpp/identifiers/IdentifiersTest.expected b/cpp/common/test/library/codingstandards/cpp/identifiers/IdentifiersTest.expected index 697666d61f..ab4c62a779 100644 --- a/cpp/common/test/library/codingstandards/cpp/identifiers/IdentifiersTest.expected +++ b/cpp/common/test/library/codingstandards/cpp/identifiers/IdentifiersTest.expected @@ -162,7 +162,7 @@ | test.cpp:244:7:244:27 | TemplateTemplateClass | test.cpp:244:7:244:27 | TemplateTemplateClass | | test.cpp:245:16:245:24 | container | test.cpp:245:16:245:24 | definition of container | | test.cpp:249:20:249:20 | T | test.cpp:249:20:249:20 | definition of T | -| test.cpp:249:53:249:53 | variable_template | test.cpp:249:53:249:53 | definition of variable_template | +| test.cpp:249:35:249:51 | variable_template | test.cpp:249:35:249:51 | definition of variable_template | | test.cpp:252:20:252:20 | T | test.cpp:252:20:252:20 | definition of T | | test.cpp:252:29:252:39 | VectorAlias | test.cpp:252:29:252:39 | definition of VectorAlias | | test.cpp:255:7:255:15 | BaseClass | test.cpp:255:7:255:15 | definition of BaseClass | diff --git a/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.expected b/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.expected index f221a5421f..1d7a675b05 100644 --- a/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.expected +++ b/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.expected @@ -1,4 +1,3 @@ | test.cpp:10:13:10:13 | 0 | 0 is used as the null-pointer-constant but is not nullptr. | | test.cpp:11:6:11:6 | 0 | 0 is used as the null-pointer-constant but is not nullptr. | | test.cpp:17:6:17:9 | 0 | NULL is used as the null-pointer-constant but is not nullptr. | -| test.cpp:18:6:18:9 | 0 | '\\0' is used as the null-pointer-constant but is not nullptr. | diff --git a/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/test.cpp b/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/test.cpp index 4be1c7a239..1e9b1b50a7 100644 --- a/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/test.cpp +++ b/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/test.cpp @@ -15,6 +15,7 @@ void test_nullptr() { int l3 = 0; // COMPLIANT - use of 0 literal with no conversion to pointer f3(f1, nullptr); // COMPLIANT - use of nullptr f1(NULL); // NON_COMPLIANT - use of NULL macro - f1('\0'); // NON_COMPLIANT - use of octal escape 0 - f3("0"); // COMPLIANT - "0" is not a literal zero -} \ No newline at end of file + // f1('\0'); // NON_COMPLIANT - use of octal escape 0 - Not accepted by + // clang or by CodeQL when mimicking clang + f3("0"); // COMPLIANT - "0" is not a literal zero +} diff --git a/cpp/common/test/rules/unusedtypedeclarations/UnusedTypeDeclarations.expected b/cpp/common/test/rules/unusedtypedeclarations/UnusedTypeDeclarations.expected index a4538f01c5..6c80382e35 100644 --- a/cpp/common/test/rules/unusedtypedeclarations/UnusedTypeDeclarations.expected +++ b/cpp/common/test/rules/unusedtypedeclarations/UnusedTypeDeclarations.expected @@ -3,8 +3,7 @@ | test.cpp:13:11:13:11 | D | Type declaration D is not used. | | test.cpp:77:11:77:11 | R | Type declaration R is not used. | | test.cpp:90:12:90:12 | (unnamed class/struct/union) | Type declaration (unnamed class/struct/union) is not used. | -| test.cpp:111:29:111:30 | AA | Type declaration AA is not used. | -| test.cpp:126:7:126:12 | Nested | Type declaration Nested is not used. | -| test.cpp:135:9:135:20 | UnusedNested | Type declaration UnusedNested is not used. | -| test.cpp:138:7:138:22 | NestedBlockScope | Type declaration NestedBlockScope is not used. | -| test.cpp:149:11:149:16 | Unused | Type declaration Unused is not used. | +| test.cpp:127:7:127:12 | Nested | Type declaration Nested is not used. | +| test.cpp:136:9:136:20 | UnusedNested | Type declaration UnusedNested is not used. | +| test.cpp:139:7:139:22 | NestedBlockScope | Type declaration NestedBlockScope is not used. | +| test.cpp:150:11:150:16 | Unused | Type declaration Unused is not used. | diff --git a/cpp/common/test/rules/unusedtypedeclarations/test.cpp b/cpp/common/test/rules/unusedtypedeclarations/test.cpp index 2c2699af04..af404ff005 100644 --- a/cpp/common/test/rules/unusedtypedeclarations/test.cpp +++ b/cpp/common/test/rules/unusedtypedeclarations/test.cpp @@ -107,8 +107,9 @@ template class X { // COMPLIANT - template class never instantiated template class Y {}; // COMPLIANT - used in the test case below // Alias templates -template using Z = Y; // COMPLIANT - used below -template using AA = Y; // NON_COMPLIANT - never instantiated +template using Z = Y; // COMPLIANT - used below +template +using AA = Y; // NON_COMPLIANT[FALSE_NEGATIVE] - never instantiated void test_alias_template() { Z v; } diff --git a/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedFunctionBinderTypedefMember.ql b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedFunctionBinderTypedefMember.ql index b31d217b71..f928457b08 100644 --- a/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedFunctionBinderTypedefMember.ql +++ b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedFunctionBinderTypedefMember.ql @@ -58,7 +58,7 @@ class FunctionTypeByNestedClass extends FunctionTypeWithBindings { } } -class DeprecatedFunctionBinderTypedefMember extends UsingAliasTypedefType { +class DeprecatedFunctionBinderTypedefMember extends TypeAliasType { ClassTemplateInstantiation cti; DeprecatedFunctionBinderTypedefMember() { diff --git a/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedStdAllocatorMember.ql b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedStdAllocatorMember.ql index 72a73a9b82..74f41437bd 100644 --- a/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedStdAllocatorMember.ql +++ b/cpp/misra/src/rules/RULE-4-1-2/UseOfDeprecatedStdAllocatorMember.ql @@ -24,7 +24,7 @@ abstract class DeprecatedUse extends Element { abstract string getAUseDescription(); } -class DeprecatedAllocatorUsingMember extends UsingAliasTypedefType, DeprecatedUse { +class DeprecatedAllocatorUsingMember extends TypeAliasType, DeprecatedUse { ClassTemplateInstantiation cti; DeprecatedAllocatorUsingMember() { diff --git a/cpp/misra/src/rules/RULE-8-7-1/PointerArithmeticFormsAnInvalidPointer.ql b/cpp/misra/src/rules/RULE-8-7-1/PointerArithmeticFormsAnInvalidPointer.ql index f2aac0b86e..aa6ee9ffde 100644 --- a/cpp/misra/src/rules/RULE-8-7-1/PointerArithmeticFormsAnInvalidPointer.ql +++ b/cpp/misra/src/rules/RULE-8-7-1/PointerArithmeticFormsAnInvalidPointer.ql @@ -18,7 +18,6 @@ import cpp import codingstandards.cpp.misra import semmle.code.cpp.ir.IR import semmle.code.cpp.dataflow.new.DataFlow -import semmle.code.cpp.ir.dataflow.internal.DataFlowUtil import semmle.code.cpp.security.BufferAccess /** @@ -159,10 +158,10 @@ class ArrayAllocation extends TArrayAllocation { * array, and the minimum estimated value for a heap-allocated one. */ int getLength(DataFlow::Node node) { - exists(IndirectUninitializedNode inode | + exists(DataFlow::IndirectUninitializedNode inode | inode = node and inode.getLocalVariable() = this.asStackAllocation().getVariable() and - result = this.asStackAllocation().getLength(inode.getIndirection()) + result = this.asStackAllocation().getLength(inode.getIndirectionIndex()) ) or node.asUninitialized() = this.asStackAllocation().getVariable() and @@ -193,33 +192,6 @@ class ArrayAllocation extends TArrayAllocation { } } -/* - * NOTE: `IndirectUninitializedNode` has made its way into `github/codeql`. Once we upgrade it to - * the version that has it, the class can be safely removed. - */ - -import semmle.code.cpp.ir.dataflow.internal.SsaImpl as SsaImpl - -class IndirectUninitializedNode extends Node { - LocalVariable v; - int indirection; - - IndirectUninitializedNode() { - exists(SsaImpl::Definition def, SsaImpl::SourceVariable sv | - def.getIndirectionIndex() = indirection and - indirection > 0 and - def.getValue().asInstruction() instanceof UninitializedInstruction and - SsaImpl::defToNode(this, def, sv) and - v = sv.getBaseVariable().(SsaImpl::BaseIRVariable).getIRVariable().getAst() - ) - } - - /** Gets the uninitialized local variable corresponding to this node. */ - LocalVariable getLocalVariable() { result = v } - - int getIndirection() { result = indirection } -} - newtype TPointerFormation = TArrayExpr(ArrayExprBA arrayExpr) or TPointerArithmetic(PointerArithmeticOperation pointerArithmetic) or diff --git a/cpp/misra/test/rules/RULE-0-2-3/UnusedTypeWithLimitedVisibility.expected b/cpp/misra/test/rules/RULE-0-2-3/UnusedTypeWithLimitedVisibility.expected index 94b7534ec0..d37b5c3263 100644 --- a/cpp/misra/test/rules/RULE-0-2-3/UnusedTypeWithLimitedVisibility.expected +++ b/cpp/misra/test/rules/RULE-0-2-3/UnusedTypeWithLimitedVisibility.expected @@ -1,5 +1,4 @@ | templates.cpp:42:12:42:13 | A1 | Type 'A1' with limited visibility is not used. | -| templates.cpp:93:11:93:12 | A1 | Type 'A1' with limited visibility is not used. | | test.cpp:5:9:5:10 | T1 | Type 'T1' with limited visibility is not used. | | test.cpp:31:8:31:9 | A2 | Type 'A2' with limited visibility is not used. | | test.cpp:61:28:61:29 | C1<> | Type 'C1<>' with limited visibility is not used. | diff --git a/cpp/misra/test/rules/RULE-0-2-3/templates.cpp b/cpp/misra/test/rules/RULE-0-2-3/templates.cpp index ebfd09299f..17c802489c 100644 --- a/cpp/misra/test/rules/RULE-0-2-3/templates.cpp +++ b/cpp/misra/test/rules/RULE-0-2-3/templates.cpp @@ -90,7 +90,7 @@ namespace use_as_template_parameter_type { * parameter */ namespace use_as_template_parameter_default_value { - class A1 { // COMPLIANT[False positive] + class A1 { // COMPLIANT static const int a = 42; }; diff --git a/cpp/misra/test/rules/RULE-7-0-6/NumericAssignmentTypeMismatch.expected b/cpp/misra/test/rules/RULE-7-0-6/NumericAssignmentTypeMismatch.expected index 068608c126..cf7fb5e402 100644 --- a/cpp/misra/test/rules/RULE-7-0-6/NumericAssignmentTypeMismatch.expected +++ b/cpp/misra/test/rules/RULE-7-0-6/NumericAssignmentTypeMismatch.expected @@ -53,41 +53,40 @@ | test.cpp:340:12:340:13 | s8 | Assignment between incompatible numeric types from 'int8_t' to 'int32_t'. | | test.cpp:342:32:342:33 | s8 | Assignment between incompatible numeric types from 'int8_t' to 'int32_t'. | | test.cpp:362:25:362:27 | u32 | Assignment between incompatible numeric types from 'uint32_t' to 'unsigned long'. | -| test.cpp:374:19:374:25 | ... + ... | Assignment between incompatible numeric types from 'int' to 'int16_t'. | -| test.cpp:379:10:379:12 | u32 | Assignment between incompatible numeric types from 'uint32_t' to 'int32_t'. | -| test.cpp:412:8:412:9 | l6 | Assignment between incompatible numeric types from 'uint32_t &' to 'uint8_t'. | -| test.cpp:413:8:413:9 | l7 | Assignment between incompatible numeric types from 'int8_t &' to 'uint8_t'. | -| test.cpp:414:9:414:10 | l8 | Assignment between incompatible numeric types from 'float &' to 'int32_t'. | -| test.cpp:425:6:425:7 | l3 | Assignment between incompatible numeric types from 'uint8_t &' to 'int64_t'. | -| test.cpp:426:6:426:7 | l4 | Assignment between incompatible numeric types from 'uint16_t &' to 'int32_t'. | -| test.cpp:437:8:437:9 | l3 | Assignment between incompatible numeric types from 'uint8_t &' to 'int8_t'. | -| test.cpp:438:8:438:9 | l4 | Assignment between incompatible numeric types from 'int8_t &' to 'uint8_t'. | -| test.cpp:451:9:451:10 | l4 | Assignment between incompatible numeric types from 'float &' to 'int32_t'. | -| test.cpp:452:7:452:8 | l5 | Assignment between incompatible numeric types from 'double &' to 'float'. | -| test.cpp:453:7:453:8 | l6 | Assignment between incompatible numeric types from 'int32_t &' to 'float'. | -| test.cpp:464:8:464:14 | ... + ... | Assignment between incompatible numeric types from 'int' to 'uint8_t'. | -| test.cpp:482:7:482:8 | l3 | Assignment between incompatible numeric types from 'uint16_t &' to 'uint32_t'. | -| test.cpp:485:7:485:8 | l5 | Assignment between incompatible numeric types from 'uint64_t &' to 'uint32_t'. | -| test.cpp:534:12:534:13 | l1 | Assignment between incompatible numeric types from 'uint32_t' to 'uint8_t'. | -| test.cpp:535:12:535:13 | l1 | Assignment between incompatible numeric types from 'uint32_t' to 'uint16_t'. | -| test.cpp:537:12:537:13 | l2 | Assignment between incompatible numeric types from 'int32_t' to 'int8_t'. | -| test.cpp:538:12:538:13 | l2 | Assignment between incompatible numeric types from 'int32_t' to 'int16_t'. | -| test.cpp:558:12:558:14 | 300 | Assignment between incompatible numeric types from 'int' to 'uint8_t'. | -| test.cpp:559:12:559:16 | 70000 | Assignment between incompatible numeric types from 'int' to 'uint16_t'. | -| test.cpp:560:12:560:27 | 4294967296 | Assignment between incompatible numeric types from 'unsigned long long' to 'uint32_t'. | -| test.cpp:561:12:561:14 | 200 | Assignment between incompatible numeric types from 'int' to 'int8_t'. | -| test.cpp:562:12:562:16 | 40000 | Assignment between incompatible numeric types from 'int' to 'int16_t'. | -| test.cpp:563:12:563:26 | 4294967296 | Assignment between incompatible numeric types from 'long long' to 'int32_t'. | -| test.cpp:564:12:564:14 | 1.0 | Assignment between incompatible numeric types from 'double' to 'float'. | -| test.cpp:565:12:565:15 | 1.0 | Assignment between incompatible numeric types from 'float' to 'double'. | -| test.cpp:570:12:570:18 | ... + ... | Assignment between incompatible numeric types from 'int' to 'uint8_t'. | -| test.cpp:571:12:571:18 | ... + ... | Assignment between incompatible numeric types from 'int' to 'uint16_t'. | -| test.cpp:572:12:572:18 | ... + ... | Assignment between incompatible numeric types from 'int' to 'uint32_t'. | -| test.cpp:574:12:574:13 | l1 | Assignment between incompatible numeric types from 'uint8_t' to 'int16_t'. | -| test.cpp:575:12:575:13 | l1 | Assignment between incompatible numeric types from 'uint8_t' to 'int32_t'. | -| test.cpp:576:12:576:13 | l1 | Assignment between incompatible numeric types from 'uint8_t' to 'float'. | -| test.cpp:577:12:577:13 | l1 | Assignment between incompatible numeric types from 'uint8_t' to 'double'. | -| test.cpp:607:9:607:37 | static_cast... | Assignment between incompatible numeric types from 'int16_t' to 'int32_t'. | +| test.cpp:380:10:380:12 | u32 | Assignment between incompatible numeric types from 'uint32_t' to 'int32_t'. | +| test.cpp:413:8:413:9 | l6 | Assignment between incompatible numeric types from 'uint32_t &' to 'uint8_t'. | +| test.cpp:414:8:414:9 | l7 | Assignment between incompatible numeric types from 'int8_t &' to 'uint8_t'. | +| test.cpp:415:9:415:10 | l8 | Assignment between incompatible numeric types from 'float &' to 'int32_t'. | +| test.cpp:426:6:426:7 | l3 | Assignment between incompatible numeric types from 'uint8_t &' to 'int64_t'. | +| test.cpp:427:6:427:7 | l4 | Assignment between incompatible numeric types from 'uint16_t &' to 'int32_t'. | +| test.cpp:438:8:438:9 | l3 | Assignment between incompatible numeric types from 'uint8_t &' to 'int8_t'. | +| test.cpp:439:8:439:9 | l4 | Assignment between incompatible numeric types from 'int8_t &' to 'uint8_t'. | +| test.cpp:452:9:452:10 | l4 | Assignment between incompatible numeric types from 'float &' to 'int32_t'. | +| test.cpp:453:7:453:8 | l5 | Assignment between incompatible numeric types from 'double &' to 'float'. | +| test.cpp:454:7:454:8 | l6 | Assignment between incompatible numeric types from 'int32_t &' to 'float'. | +| test.cpp:465:8:465:14 | ... + ... | Assignment between incompatible numeric types from 'int' to 'uint8_t'. | +| test.cpp:483:7:483:8 | l3 | Assignment between incompatible numeric types from 'uint16_t &' to 'uint32_t'. | +| test.cpp:486:7:486:8 | l5 | Assignment between incompatible numeric types from 'uint64_t &' to 'uint32_t'. | +| test.cpp:535:12:535:13 | l1 | Assignment between incompatible numeric types from 'uint32_t' to 'uint8_t'. | +| test.cpp:536:12:536:13 | l1 | Assignment between incompatible numeric types from 'uint32_t' to 'uint16_t'. | +| test.cpp:538:12:538:13 | l2 | Assignment between incompatible numeric types from 'int32_t' to 'int8_t'. | +| test.cpp:539:12:539:13 | l2 | Assignment between incompatible numeric types from 'int32_t' to 'int16_t'. | +| test.cpp:559:12:559:14 | 300 | Assignment between incompatible numeric types from 'int' to 'uint8_t'. | +| test.cpp:560:12:560:16 | 70000 | Assignment between incompatible numeric types from 'int' to 'uint16_t'. | +| test.cpp:561:12:561:27 | 4294967296 | Assignment between incompatible numeric types from 'unsigned long long' to 'uint32_t'. | +| test.cpp:562:12:562:14 | 200 | Assignment between incompatible numeric types from 'int' to 'int8_t'. | +| test.cpp:563:12:563:16 | 40000 | Assignment between incompatible numeric types from 'int' to 'int16_t'. | +| test.cpp:564:12:564:26 | 4294967296 | Assignment between incompatible numeric types from 'long long' to 'int32_t'. | +| test.cpp:565:12:565:14 | 1.0 | Assignment between incompatible numeric types from 'double' to 'float'. | +| test.cpp:566:12:566:15 | 1.0 | Assignment between incompatible numeric types from 'float' to 'double'. | +| test.cpp:571:12:571:18 | ... + ... | Assignment between incompatible numeric types from 'int' to 'uint8_t'. | +| test.cpp:572:12:572:18 | ... + ... | Assignment between incompatible numeric types from 'int' to 'uint16_t'. | +| test.cpp:573:12:573:18 | ... + ... | Assignment between incompatible numeric types from 'int' to 'uint32_t'. | +| test.cpp:575:12:575:13 | l1 | Assignment between incompatible numeric types from 'uint8_t' to 'int16_t'. | +| test.cpp:576:12:576:13 | l1 | Assignment between incompatible numeric types from 'uint8_t' to 'int32_t'. | +| test.cpp:577:12:577:13 | l1 | Assignment between incompatible numeric types from 'uint8_t' to 'float'. | +| test.cpp:578:12:578:13 | l1 | Assignment between incompatible numeric types from 'uint8_t' to 'double'. | +| test.cpp:608:9:608:37 | static_cast... | Assignment between incompatible numeric types from 'int16_t' to 'int32_t'. | | test_aggregate.cpp:29:22:29:24 | u16 | Assignment between incompatible numeric types from 'uint16_t' to 'uint8_t'. | | test_aggregate.cpp:31:26:31:28 | u32 | Assignment between incompatible numeric types from 'uint32_t' to 'uint16_t'. | | test_aggregate.cpp:33:31:33:33 | u32 | Assignment between incompatible numeric types from 'uint32_t' to 'int32_t'. | diff --git a/cpp/misra/test/rules/RULE-7-0-6/test.cpp b/cpp/misra/test/rules/RULE-7-0-6/test.cpp index 35aca81707..f076d18ede 100644 --- a/cpp/misra/test/rules/RULE-7-0-6/test.cpp +++ b/cpp/misra/test/rules/RULE-7-0-6/test.cpp @@ -368,11 +368,12 @@ void test_template_functions() { // Test initialization forms std::int32_t f12(std::int8_t l1) { - std::int16_t l2 = l1; // COMPLIANT - std::int16_t l3{l1}; // COMPLIANT - std::int16_t l4(l1); // COMPLIANT - std::int16_t l5{l1 + l1}; // NON_COMPLIANT - return l1; // COMPLIANT + std::int16_t l2 = l1; // COMPLIANT + std::int16_t l3{l1}; // COMPLIANT + std::int16_t l4(l1); // COMPLIANT + // std::int16_t l5{l1 + l1}; // NON_COMPLIANT - Not accepted by clang or by + // CodeQL when mimicking clang + return l1; // COMPLIANT } std::int32_t test_return() { @@ -640,4 +641,4 @@ void test_explicit_casts() { // Function calls with explicit casts f1(static_cast(l4)); // COMPLIANT f2(static_cast(l4)); // COMPLIANT -} \ No newline at end of file +}