diff --git a/c/cert/src/rules/INT30-C/UnsignedIntegerOperationsWrapAround.ql b/c/cert/src/rules/INT30-C/UnsignedIntegerOperationsWrapAround.ql index 3d25313915..1c7ae3e31b 100644 --- a/c/cert/src/rules/INT30-C/UnsignedIntegerOperationsWrapAround.ql +++ b/c/cert/src/rules/INT30-C/UnsignedIntegerOperationsWrapAround.ql @@ -15,24 +15,11 @@ import cpp import codingstandards.c.cert -import codingstandards.cpp.Overflow -import semmle.code.cpp.controlflow.Guards -import semmle.code.cpp.valuenumbering.GlobalValueNumbering +import codingstandards.cpp.rules.unsignedoperationwithconstantoperandswraps.UnsignedOperationWithConstantOperandsWraps -from InterestingOverflowingOperation op -where - not isExcluded(op, IntegerOverflowPackage::unsignedIntegerOperationsWrapAroundQuery()) and - op.getType().getUnderlyingType().(IntegralType).isUnsigned() and - // Not within a guard condition - not exists(GuardCondition gc | gc.getAChild*() = op) and - // Not guarded by a check, where the check is not an invalid overflow check - not op.hasValidPreCheck() and - // Is not checked after the operation - not op.hasValidPostCheck() and - // Permitted by exception 3 - not op instanceof LShiftExpr and - // Permitted by exception 2 - zero case is handled in separate query - not op instanceof DivExpr and - not op instanceof RemExpr -select op, - "Operation " + op.getOperator() + " of type " + op.getType().getUnderlyingType() + " may wrap." +class UnsignedIntegerOperationsWrapAroundQuery extends UnsignedOperationWithConstantOperandsWrapsSharedQuery +{ + UnsignedIntegerOperationsWrapAroundQuery() { + this = IntegerOverflowPackage::unsignedIntegerOperationsWrapAroundQuery() + } +} diff --git a/c/cert/test/rules/INT30-C/UnsignedIntegerOperationsWrapAround.expected b/c/cert/test/rules/INT30-C/UnsignedIntegerOperationsWrapAround.expected deleted file mode 100644 index 76594d944b..0000000000 --- a/c/cert/test/rules/INT30-C/UnsignedIntegerOperationsWrapAround.expected +++ /dev/null @@ -1,4 +0,0 @@ -| test.c:4:3:4:9 | ... + ... | Operation + of type unsigned int may wrap. | -| test.c:5:3:5:10 | ... += ... | Operation += of type unsigned int may wrap. | -| test.c:58:3:58:9 | ... - ... | Operation - of type unsigned int may wrap. | -| test.c:59:3:59:10 | ... -= ... | Operation -= of type unsigned int may wrap. | diff --git a/c/cert/test/rules/INT30-C/UnsignedIntegerOperationsWrapAround.qlref b/c/cert/test/rules/INT30-C/UnsignedIntegerOperationsWrapAround.qlref deleted file mode 100644 index 045890904c..0000000000 --- a/c/cert/test/rules/INT30-C/UnsignedIntegerOperationsWrapAround.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/INT30-C/UnsignedIntegerOperationsWrapAround.ql \ No newline at end of file diff --git a/c/cert/test/rules/INT30-C/UnsignedIntegerOperationsWrapAround.testref b/c/cert/test/rules/INT30-C/UnsignedIntegerOperationsWrapAround.testref new file mode 100644 index 0000000000..c9bc9d9637 --- /dev/null +++ b/c/cert/test/rules/INT30-C/UnsignedIntegerOperationsWrapAround.testref @@ -0,0 +1 @@ +c/common/test/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.ql \ No newline at end of file diff --git a/c/cert/test/rules/MSC30-C/RandUsedForGeneratingPseudorandomNumbers.testref b/c/cert/test/rules/MSC30-C/RandUsedForGeneratingPseudorandomNumbers.testref index 31cba60b74..726f27535d 100644 --- a/c/cert/test/rules/MSC30-C/RandUsedForGeneratingPseudorandomNumbers.testref +++ b/c/cert/test/rules/MSC30-C/RandUsedForGeneratingPseudorandomNumbers.testref @@ -1 +1 @@ -cpp/common/test/rules/donotuserandforgeneratingpseudorandomnumbers/DoNotUseRandForGeneratingPseudorandomNumbers.ql \ No newline at end of file +c/common/test/rules/donotuserandforgeneratingpseudorandomnumbers/DoNotUseRandForGeneratingPseudorandomNumbers.ql \ No newline at end of file diff --git a/c/common/src/codingstandards/c/Literals.qll b/c/common/src/codingstandards/c/Literals.qll deleted file mode 100644 index beeeccb8cc..0000000000 --- a/c/common/src/codingstandards/c/Literals.qll +++ /dev/null @@ -1,4 +0,0 @@ -// Reuse the `IntegerLiteral` class -import codingstandards.cpp.Cpp14Literal - -class IntegerLiteral = Cpp14Literal::IntegerLiteral; diff --git a/c/misra/test/rules/RULE-20-12/MacroParameterUsedAsHashOperand.expected b/c/common/test/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.expected similarity index 58% rename from c/misra/test/rules/RULE-20-12/MacroParameterUsedAsHashOperand.expected rename to c/common/test/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.expected index be347218b3..d5f6f296d9 100644 --- a/c/misra/test/rules/RULE-20-12/MacroParameterUsedAsHashOperand.expected +++ b/c/common/test/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.expected @@ -1,2 +1,2 @@ -| test.c:4:1:4:41 | #define BAD_MACRO_WITH_ARG(x) (x) + wow ## x | Macro BAD_MACRO_WITH_ARG contains use of parameter x used in multiple contexts. | -| test.c:5:1:5:48 | #define BAD_MACRO_WITH_ARG_TWO(x,y) (x) + wow ## x | Macro BAD_MACRO_WITH_ARG_TWO contains use of parameter x used in multiple contexts. | +| test.c:5:1:5:41 | #define BAD_MACRO_WITH_ARG(x) (x) + wow ## x | Macro BAD_MACRO_WITH_ARG contains use of parameter x used in multiple contexts. | +| test.c:6:1:6:48 | #define BAD_MACRO_WITH_ARG_TWO(x,y) (x) + wow ## x | Macro BAD_MACRO_WITH_ARG_TWO contains use of parameter x used in multiple contexts. | diff --git a/c/common/test/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.ql b/c/common/test/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.ql new file mode 100644 index 0000000000..5aa514e86d --- /dev/null +++ b/c/common/test/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.amixedusemacroargumentsubjecttoexpansion.AMixedUseMacroArgumentSubjectToExpansion + +class TestFileQuery extends AMixedUseMacroArgumentSubjectToExpansionSharedQuery, TestQuery { } diff --git a/c/common/test/rules/amixedusemacroargumentsubjecttoexpansion/test.c b/c/common/test/rules/amixedusemacroargumentsubjecttoexpansion/test.c new file mode 100644 index 0000000000..7eb5e204c7 --- /dev/null +++ b/c/common/test/rules/amixedusemacroargumentsubjecttoexpansion/test.c @@ -0,0 +1,26 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +#define GOOD_MACRO_WITH_ARG(X) ((X)*X##_scale) // COMPLIANT +#define MACRO 1 +#define BAD_MACRO_WITH_ARG(x) (x) + wow##x // NON_COMPLIANT +#define BAD_MACRO_WITH_ARG_TWO(x, y) (x) + wow##x // NON_COMPLIANT +#define MACROONE(x) #x // COMPLIANT +#define MACROTWO(x) x *x // COMPLIANT +#define MACROTHREE(x) "##\"\"'" + (x) // COMPLIANT +#define FOO(x) #x MACROONE(x) // COMPLIANT - no further arg expansion + +void f() { + + int x; + int x_scale; + int y; + int wowMACRO = 0; + + y = GOOD_MACRO_WITH_ARG(x); + wowMACRO = BAD_MACRO_WITH_ARG(MACRO); + wowMACRO = BAD_MACRO_WITH_ARG_TWO(MACRO, 1); + char s[] = MACROONE(MACRO); + y = MACROTWO(MACRO); + MACROTHREE(MACRO); + FOO(x); +} \ No newline at end of file diff --git a/c/common/test/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.expected b/c/common/test/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.expected new file mode 100644 index 0000000000..489a990582 --- /dev/null +++ b/c/common/test/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.expected @@ -0,0 +1,4 @@ +| test.c:8:14:8:17 | call to atof | Call to banned function atof. | +| test.c:9:12:9:15 | call to atoi | Call to banned function atoi. | +| test.c:10:13:10:16 | call to atol | Call to banned function atol. | +| test.c:11:18:11:22 | call to atoll | Call to banned function atoll. | diff --git a/c/common/test/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.ql b/c/common/test/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.ql new file mode 100644 index 0000000000..6da5fe6097 --- /dev/null +++ b/c/common/test/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.atofatoiatolandatollused.AtofAtoiAtolAndAtollUsed + +class TestFileQuery extends AtofAtoiAtolAndAtollUsedSharedQuery, TestQuery { } diff --git a/c/common/test/rules/atofatoiatolandatollused/test.c b/c/common/test/rules/atofatoiatolandatollused/test.c new file mode 100644 index 0000000000..f8140af79a --- /dev/null +++ b/c/common/test/rules/atofatoiatolandatollused/test.c @@ -0,0 +1,13 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +#include +#include +void f2(); +void f1() { + char l1[5] = "abcd"; + float l2 = atof(l1); // NON_COMLIANT + int l3 = atoi(l1); // NON_COMPLIANT + long l4 = atol(l1); // NON_COMPLIANT + long long l5 = atoll(l1); // NON_COMPLIANT + f2(); // COMPLIANT +} diff --git a/c/common/test/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.expected b/c/common/test/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.expected new file mode 100644 index 0000000000..f04b1b6ce9 --- /dev/null +++ b/c/common/test/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.expected @@ -0,0 +1,4 @@ +| test.c:8:7:8:8 | x1 | Bit-field 'x1' is declared on type 'int'. | +| test.c:12:15:12:16 | x5 | Bit-field 'x5' is declared on type 'signed long'. | +| test.c:14:15:14:16 | x6 | Bit-field 'x6' is declared on type 'signed char'. | +| test.c:16:14:16:15 | x7 | Bit-field 'x7' is declared on type 'Color'. | diff --git a/c/common/test/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.ql b/c/common/test/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.ql new file mode 100644 index 0000000000..a3e1ecc76c --- /dev/null +++ b/c/common/test/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.bitfieldshallhaveanappropriatetype.BitFieldShallHaveAnAppropriateType + +class TestFileQuery extends BitFieldShallHaveAnAppropriateTypeSharedQuery, TestQuery { } diff --git a/c/common/test/rules/bitfieldshallhaveanappropriatetype/test.c b/c/common/test/rules/bitfieldshallhaveanappropriatetype/test.c new file mode 100644 index 0000000000..c418e0e4fc --- /dev/null +++ b/c/common/test/rules/bitfieldshallhaveanappropriatetype/test.c @@ -0,0 +1,17 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +typedef unsigned int UINT16; + +enum Color { R, G, B }; + +struct SampleStruct { + int x1 : 2; // NON_COMPLIANT - not explicitly signed or unsigned + unsigned int x2 : 2; // COMPLIANT - explicitly unsigned + signed int x3 : 2; // COMPLIANT - explicitly signed + UINT16 x4 : 2; // COMPLIANT - type alias resolves to a compliant type + signed long x5 : 2; // NON_COMPLIANT - cannot declare bit field for long, even + // if it's signed + signed char x6 : 2; // NON_COMPLIANT - cannot declare bit field for char, even + // if it's signed + enum Color x7 : 3; // NON_COMPLIANT - cannot declare bit field for enum +} sample_struct; diff --git a/c/common/test/rules/constlikereturnvalue/ConstLikeReturnValue.expected b/c/common/test/rules/constlikereturnvalue/ConstLikeReturnValue.expected index 94e63062c5..99d91f7575 100644 --- a/c/common/test/rules/constlikereturnvalue/ConstLikeReturnValue.expected +++ b/c/common/test/rules/constlikereturnvalue/ConstLikeReturnValue.expected @@ -1,20 +1,20 @@ problems -| test.c:8:8:8:12 | c_str | test.c:15:16:15:21 | call to getenv | test.c:8:8:8:12 | c_str | The object returned by the function getenv should not be modified. | -| test.c:64:5:64:9 | conv4 | test.c:61:11:61:20 | call to localeconv | test.c:64:5:64:9 | conv4 | The object returned by the function localeconv should not be modified. | -| test.c:73:5:73:8 | conv | test.c:69:25:69:34 | call to localeconv | test.c:73:5:73:8 | conv | The object returned by the function localeconv should not be modified. | +| test.c:11:8:11:12 | c_str | test.c:18:16:18:21 | call to getenv | test.c:11:8:11:12 | c_str | The object returned by the function getenv should not be modified. | +| test.c:67:5:67:9 | conv4 | test.c:64:11:64:20 | call to localeconv | test.c:67:5:67:9 | conv4 | The object returned by the function localeconv should not be modified. | +| test.c:76:5:76:8 | conv | test.c:72:25:72:34 | call to localeconv | test.c:76:5:76:8 | conv | The object returned by the function localeconv should not be modified. | edges -| test.c:5:18:5:22 | c_str | test.c:8:8:8:12 | c_str | -| test.c:15:16:15:21 | call to getenv | test.c:21:9:21:12 | env1 | -| test.c:21:9:21:12 | env1 | test.c:5:18:5:22 | c_str | -| test.c:61:11:61:20 | call to localeconv | test.c:64:5:64:9 | conv4 | -| test.c:69:25:69:34 | call to localeconv | test.c:73:5:73:8 | conv | +| test.c:8:18:8:22 | c_str | test.c:11:8:11:12 | c_str | +| test.c:18:16:18:21 | call to getenv | test.c:24:9:24:12 | env1 | +| test.c:24:9:24:12 | env1 | test.c:8:18:8:22 | c_str | +| test.c:64:11:64:20 | call to localeconv | test.c:67:5:67:9 | conv4 | +| test.c:72:25:72:34 | call to localeconv | test.c:76:5:76:8 | conv | nodes -| test.c:5:18:5:22 | c_str | semmle.label | c_str | -| test.c:8:8:8:12 | c_str | semmle.label | c_str | -| test.c:15:16:15:21 | call to getenv | semmle.label | call to getenv | -| test.c:21:9:21:12 | env1 | semmle.label | env1 | -| test.c:61:11:61:20 | call to localeconv | semmle.label | call to localeconv | -| test.c:64:5:64:9 | conv4 | semmle.label | conv4 | -| test.c:69:25:69:34 | call to localeconv | semmle.label | call to localeconv | -| test.c:73:5:73:8 | conv | semmle.label | conv | +| test.c:8:18:8:22 | c_str | semmle.label | c_str | +| test.c:11:8:11:12 | c_str | semmle.label | c_str | +| test.c:18:16:18:21 | call to getenv | semmle.label | call to getenv | +| test.c:24:9:24:12 | env1 | semmle.label | env1 | +| test.c:64:11:64:20 | call to localeconv | semmle.label | call to localeconv | +| test.c:67:5:67:9 | conv4 | semmle.label | conv4 | +| test.c:72:25:72:34 | call to localeconv | semmle.label | call to localeconv | +| test.c:76:5:76:8 | conv | semmle.label | conv | subpaths diff --git a/c/common/test/rules/constlikereturnvalue/test.c b/c/common/test/rules/constlikereturnvalue/test.c index cd7c101898..e28c05961f 100644 --- a/c/common/test/rules/constlikereturnvalue/test.c +++ b/c/common/test/rules/constlikereturnvalue/test.c @@ -1,4 +1,7 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. #include +#include #include #include diff --git a/c/common/test/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.expected b/c/common/test/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.expected new file mode 100644 index 0000000000..c9a9eb0d48 --- /dev/null +++ b/c/common/test/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.expected @@ -0,0 +1,2 @@ +| test.c:8:1:8:25 | #define MACRO4(x) (x + 1) | Macro used instead of a function. | +| test.c:13:1:13:48 | #define MACRO9() printf_custom("output = %d", 7) | Macro used instead of a function. | diff --git a/c/common/test/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.ql b/c/common/test/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.ql new file mode 100644 index 0000000000..29088c4458 --- /dev/null +++ b/c/common/test/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.functionlikemacrosdefined.FunctionLikeMacrosDefined + +class TestFileQuery extends FunctionLikeMacrosDefinedSharedQuery, TestQuery { } diff --git a/c/common/test/rules/functionlikemacrosdefined/test.c b/c/common/test/rules/functionlikemacrosdefined/test.c new file mode 100644 index 0000000000..ee36549b8d --- /dev/null +++ b/c/common/test/rules/functionlikemacrosdefined/test.c @@ -0,0 +1,42 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +#include + +#define MACRO(OP, L, R) ((L)OP(R)) // COMPLIANT +#define MACRO2(L, R) (L + R) // COMPLIANT +#define MACRO3(L, R) (L " " R " " L) // COMPLIANT +#define MACRO4(x) (x + 1) // NON_COMPLIANT +#define MACRO5(L, LR) (LR + 1) // COMPLIANT +#define MACRO6(x) printf_custom("output = %d", test##x) // COMPLIANT +#define MACRO7(x) #x // COMPLIANT +#define MACRO8(x) "NOP" // COMPLIANT +#define MACRO9() printf_custom("output = %d", 7) // NON_COMPLIANT +#define MACRO10(x) // COMPLIANT +#define MY_ASSERT(X) assert(X) // NON_COMPLIANT[FALSE_NEGATIVE] + +char a1[MACRO2(1, 1) + 6]; +extern int printf_custom(char *, int); +int test1; + +void f() { + int i = MACRO(+, 1, 1); + int i2 = MACRO2(7, 10); + + static int i3 = MACRO2(1, 1); + + char *i4 = MACRO3("prefix", "suffix"); + + int i5 = MACRO4(1); + + int i6 = MACRO4(MACRO2(1, 1)); + + int i7 = MACRO5(1, 1); + + MACRO6(1); + + char *i10 = MACRO7("prefix"); + + asm(MACRO8(1)); + + MY_ASSERT(1); +} \ No newline at end of file diff --git a/c/common/test/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.expected b/c/common/test/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.expected new file mode 100644 index 0000000000..7fd94b47f3 --- /dev/null +++ b/c/common/test/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.expected @@ -0,0 +1,3 @@ +| test.c:4:3:4:10 | goto ... | The goto statement and its $@ are not declared or enclosed in the same block. | test.c:6:3:6:5 | label ...: | label | +| test.c:42:3:42:10 | goto ... | The goto statement and its $@ are not declared or enclosed in the same block. | test.c:46:3:46:5 | label ...: | label | +| test.c:57:5:57:12 | goto ... | The goto statement and its $@ are not declared or enclosed in the same block. | test.c:60:3:60:5 | label ...: | label | diff --git a/c/common/test/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.ql b/c/common/test/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.ql new file mode 100644 index 0000000000..f553135683 --- /dev/null +++ b/c/common/test/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.gotoreferencealabelinsurroundingblock.GotoReferenceALabelInSurroundingBlock + +class TestFileQuery extends GotoReferenceALabelInSurroundingBlockSharedQuery, TestQuery { } diff --git a/c/misra/test/rules/RULE-15-3/test.c b/c/common/test/rules/gotoreferencealabelinsurroundingblock/test.c similarity index 88% rename from c/misra/test/rules/RULE-15-3/test.c rename to c/common/test/rules/gotoreferencealabelinsurroundingblock/test.c index 739affcfc1..083e0fe57b 100644 --- a/c/misra/test/rules/RULE-15-3/test.c +++ b/c/common/test/rules/gotoreferencealabelinsurroundingblock/test.c @@ -1,3 +1,5 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. void f1() { goto L1; for (int i = 0; i < 100; i++) { diff --git a/c/common/test/rules/gotostatementcondition/GotoStatementCondition.expected b/c/common/test/rules/gotostatementcondition/GotoStatementCondition.expected index e522289c7b..c42642c343 100644 --- a/c/common/test/rules/gotostatementcondition/GotoStatementCondition.expected +++ b/c/common/test/rules/gotostatementcondition/GotoStatementCondition.expected @@ -1,3 +1,4 @@ -| test.c:5:3:5:10 | goto ... | The $@ statement jumps to a $@ that is not declared later in the same function. | test.c:5:3:5:10 | goto ... | L1 | test.c:2:1:2:3 | label ...: | label ...: | -| test.c:14:3:14:10 | goto ... | The $@ statement jumps to a $@ that is not declared later in the same function. | test.c:14:3:14:10 | goto ... | L2 | test.c:12:1:12:3 | label ...: | label ...: | -| test.c:16:3:16:10 | goto ... | The $@ statement jumps to a $@ that is not declared later in the same function. | test.c:16:3:16:10 | goto ... | L1 | test.c:11:1:11:3 | label ...: | label ...: | +| test.c:9:3:9:10 | goto ... | The $@ statement jumps to a $@ that is not declared later in the same function. | test.c:9:3:9:10 | goto ... | l1 | test.c:5:1:5:3 | label ...: | label ...: | +| test.c:21:3:21:10 | goto ... | The $@ statement jumps to a $@ that is not declared later in the same function. | test.c:21:3:21:10 | goto ... | l2 | test.c:17:1:17:3 | label ...: | label ...: | +| test.c:23:3:23:10 | goto ... | The $@ statement jumps to a $@ that is not declared later in the same function. | test.c:23:3:23:10 | goto ... | l1 | test.c:16:1:16:3 | label ...: | label ...: | +| test.c:28:3:28:10 | goto ... | The $@ statement jumps to a $@ that is not declared later in the same function. | test.c:28:3:28:10 | goto ... | l1 | test.c:27:1:27:3 | label ...: | label ...: | diff --git a/c/common/test/rules/gotostatementcondition/test.c b/c/common/test/rules/gotostatementcondition/test.c index 2c189cd433..48426261fe 100644 --- a/c/common/test/rules/gotostatementcondition/test.c +++ b/c/common/test/rules/gotostatementcondition/test.c @@ -1,17 +1,29 @@ -void f1() { -L1:; - goto L2; // COMPLIANT - ; - goto L1; // NON_COMPLIANT +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +void f1(int p1) { -L2:; +l1: + if (p1) { + goto l2; // COMPLIANT + } + goto l1; // NON_COMPLIANT + +l2:; } -void f2() { -L1:; -L2: - goto L3; // COMPLIANT - goto L2; // NON_COMPLIANT -L3: - goto L1; // NON_COMPLIANT +void f2(int p1) { + +l1:; +l2: + if (p1) { + goto l3; // COMPLIANT + } + goto l2; // NON_COMPLIANT +l3: + goto l1; // NON_COMPLIANT } + +void f3() { +l1: + goto l1; // NON_COMPLIANT +} \ No newline at end of file diff --git a/c/common/test/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.expected b/c/common/test/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.expected new file mode 100644 index 0000000000..15dc49ee37 --- /dev/null +++ b/c/common/test/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.expected @@ -0,0 +1 @@ +| test.c:6:3:6:14 | goto ... | Use of goto. | diff --git a/c/common/test/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.ql b/c/common/test/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.ql new file mode 100644 index 0000000000..1a117d5ddd --- /dev/null +++ b/c/common/test/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.gotostatementshouldnotbeused.GotoStatementShouldNotBeUsed + +class TestFileQuery extends GotoStatementShouldNotBeUsedSharedQuery, TestQuery { } diff --git a/c/common/test/rules/gotostatementshouldnotbeused/test.c b/c/common/test/rules/gotostatementshouldnotbeused/test.c new file mode 100644 index 0000000000..4ecc1789c7 --- /dev/null +++ b/c/common/test/rules/gotostatementshouldnotbeused/test.c @@ -0,0 +1,11 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +void test_goto() { + int x = 1; + + goto label1; // NON_COMPLIANT + +label1: + + x = 2; +} \ No newline at end of file diff --git a/c/common/test/rules/invalidatedenvstringpointers/InvalidatedEnvStringPointers.expected b/c/common/test/rules/invalidatedenvstringpointers/InvalidatedEnvStringPointers.expected index c52544450f..9270a5ac15 100644 --- a/c/common/test/rules/invalidatedenvstringpointers/InvalidatedEnvStringPointers.expected +++ b/c/common/test/rules/invalidatedenvstringpointers/InvalidatedEnvStringPointers.expected @@ -1,6 +1,6 @@ -| test.c:19:14:19:19 | tmpvar | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:11:12:11:17 | call to getenv | call to getenv | test.c:15:13:15:18 | call to getenv | call to getenv | -| test.c:132:14:132:17 | temp | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:128:12:128:17 | call to getenv | call to getenv | test.c:129:11:129:16 | call to getenv | call to getenv | -| test.c:132:20:132:22 | tmp | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:129:11:129:16 | call to getenv | call to getenv | test.c:128:12:128:17 | call to getenv | call to getenv | -| test.c:163:14:163:26 | tmpvar_global | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:155:19:155:24 | call to getenv | call to getenv | test.c:159:20:159:25 | call to getenv | call to getenv | -| test.c:186:18:186:18 | r | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:183:7:183:15 | call to setlocale | call to setlocale | test.c:185:8:185:17 | call to localeconv | call to localeconv | -| test.c:206:10:206:15 | tmpvar | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:200:12:200:17 | call to getenv | call to getenv | test.c:204:3:204:8 | call to f11fun | call to f11fun | +| test.c:21:14:21:19 | tmpvar | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:13:12:13:17 | call to getenv | call to getenv | test.c:17:13:17:18 | call to getenv | call to getenv | +| test.c:134:14:134:17 | temp | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:130:12:130:17 | call to getenv | call to getenv | test.c:131:11:131:16 | call to getenv | call to getenv | +| test.c:134:20:134:22 | tmp | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:131:11:131:16 | call to getenv | call to getenv | test.c:130:12:130:17 | call to getenv | call to getenv | +| test.c:165:14:165:26 | tmpvar_global | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:157:19:157:24 | call to getenv | call to getenv | test.c:161:20:161:25 | call to getenv | call to getenv | +| test.c:188:18:188:18 | r | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:185:7:185:15 | call to setlocale | call to setlocale | test.c:187:8:187:17 | call to localeconv | call to localeconv | +| test.c:208:10:208:15 | tmpvar | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.c:202:12:202:17 | call to getenv | call to getenv | test.c:206:3:206:8 | call to f11fun | call to f11fun | diff --git a/c/common/test/rules/invalidatedenvstringpointers/test.c b/c/common/test/rules/invalidatedenvstringpointers/test.c index 59c9593d21..183a4891c1 100644 --- a/c/common/test/rules/invalidatedenvstringpointers/test.c +++ b/c/common/test/rules/invalidatedenvstringpointers/test.c @@ -1,3 +1,5 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. #include #include #include diff --git a/c/common/test/rules/invalidatedenvstringpointerswarn/InvalidatedEnvStringPointersWarn.expected b/c/common/test/rules/invalidatedenvstringpointerswarn/InvalidatedEnvStringPointersWarn.expected index 556a3fe4a8..628a4f99d6 100644 --- a/c/common/test/rules/invalidatedenvstringpointerswarn/InvalidatedEnvStringPointersWarn.expected +++ b/c/common/test/rules/invalidatedenvstringpointerswarn/InvalidatedEnvStringPointersWarn.expected @@ -1,2 +1,2 @@ -| test.c:13:19:13:24 | call to getenv | The value of variable $@ might become invalid after a subsequent call to function `getenv`. | test.c:10:7:10:19 | tmpvar_global | tmpvar_global | -| test.c:16:20:16:25 | call to getenv | The value of variable $@ might become invalid after a subsequent call to function `getenv`. | test.c:7:9:7:20 | tmpvar_field | tmpvar_field | +| test.c:15:19:15:24 | call to getenv | The value of variable $@ might become invalid after a subsequent call to function `getenv`. | test.c:12:7:12:19 | tmpvar_global | tmpvar_global | +| test.c:18:20:18:25 | call to getenv | The value of variable $@ might become invalid after a subsequent call to function `getenv`. | test.c:9:9:9:20 | tmpvar_field | tmpvar_field | diff --git a/c/common/test/rules/invalidatedenvstringpointerswarn/test.c b/c/common/test/rules/invalidatedenvstringpointerswarn/test.c index 2b678df6ac..6d4cec1d8d 100644 --- a/c/common/test/rules/invalidatedenvstringpointerswarn/test.c +++ b/c/common/test/rules/invalidatedenvstringpointerswarn/test.c @@ -1,3 +1,5 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. #include #include #include diff --git a/c/common/test/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.expected b/c/common/test/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.expected new file mode 100644 index 0000000000..a381fdb7e8 --- /dev/null +++ b/c/common/test/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.expected @@ -0,0 +1,16 @@ +| test.c:5:10:5:11 | 0 | Lowercase 'l' used as a literal suffix. | +| test.c:6:10:6:12 | 0 | Lowercase 'l' used as a literal suffix. | +| test.c:9:10:9:12 | 0 | Lowercase 'l' used as a literal suffix. | +| test.c:10:10:10:12 | 0 | Lowercase 'l' used as a literal suffix. | +| test.c:15:11:15:12 | 0 | Lowercase 'l' used as a literal suffix. | +| test.c:16:11:16:13 | 0 | Lowercase 'l' used as a literal suffix. | +| test.c:19:11:19:13 | 0 | Lowercase 'l' used as a literal suffix. | +| test.c:20:11:20:13 | 0 | Lowercase 'l' used as a literal suffix. | +| test.c:25:10:25:14 | 1 | Lowercase 'l' used as a literal suffix. | +| test.c:26:10:26:15 | 1 | Lowercase 'l' used as a literal suffix. | +| test.c:29:10:29:15 | 1 | Lowercase 'l' used as a literal suffix. | +| test.c:30:10:30:15 | 1 | Lowercase 'l' used as a literal suffix. | +| test.c:35:11:35:14 | 1 | Lowercase 'l' used as a literal suffix. | +| test.c:36:11:36:15 | 1 | Lowercase 'l' used as a literal suffix. | +| test.c:39:11:39:15 | 1 | Lowercase 'l' used as a literal suffix. | +| test.c:40:11:40:15 | 1 | Lowercase 'l' used as a literal suffix. | diff --git a/c/common/test/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.ql b/c/common/test/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.ql new file mode 100644 index 0000000000..ab353ca8a9 --- /dev/null +++ b/c/common/test/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.lowercaselstartsinliteralsuffix.LowercaseLStartsInLiteralSuffix + +class TestFileQuery extends LowercaseLStartsInLiteralSuffixSharedQuery, TestQuery { } diff --git a/c/misra/test/rules/RULE-7-3/test.c b/c/common/test/rules/lowercaselstartsinliteralsuffix/test.c similarity index 86% rename from c/misra/test/rules/RULE-7-3/test.c rename to c/common/test/rules/lowercaselstartsinliteralsuffix/test.c index 5e1c448926..549e90bd7d 100644 --- a/c/misra/test/rules/RULE-7-3/test.c +++ b/c/common/test/rules/lowercaselstartsinliteralsuffix/test.c @@ -1,4 +1,6 @@ - +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +// int x = false; // COMPLIANT - reported as C++ FP in #319 int a1 = 0L; // COMPLIANT int a2 = 0l; // NON_COMPLIANT int a3 = 0ll; // NON_COMPLIANT diff --git a/c/common/test/rules/macroparameterfollowinghash/MacroParameterFollowingHash.expected b/c/common/test/rules/macroparameterfollowinghash/MacroParameterFollowingHash.expected new file mode 100644 index 0000000000..715bbe781d --- /dev/null +++ b/c/common/test/rules/macroparameterfollowinghash/MacroParameterFollowingHash.expected @@ -0,0 +1 @@ +| test.c:27:1:27:29 | #define MACROTHIRTEEN(X) #X ## X | Macro definition uses an # operator followed by a ## operator. | diff --git a/c/common/test/rules/macroparameterfollowinghash/MacroParameterFollowingHash.ql b/c/common/test/rules/macroparameterfollowinghash/MacroParameterFollowingHash.ql new file mode 100644 index 0000000000..f753b75463 --- /dev/null +++ b/c/common/test/rules/macroparameterfollowinghash/MacroParameterFollowingHash.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.macroparameterfollowinghash.MacroParameterFollowingHash + +class TestFileQuery extends MacroParameterFollowingHashSharedQuery, TestQuery { } diff --git a/c/common/test/rules/macroparameterfollowinghash/test.c b/c/common/test/rules/macroparameterfollowinghash/test.c new file mode 100644 index 0000000000..d998ce8106 --- /dev/null +++ b/c/common/test/rules/macroparameterfollowinghash/test.c @@ -0,0 +1,29 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +#define MACROONE 1 // COMPLIANT + +#define MACROTWO '#\'-#' + '#' // COMPLIANT + +#define MACROTHREE "##" // COMPLIANT + +#define MACROFOUR "##" + "#" // COMPLIANT + +#define MACROFIVE(X) #X // COMPLIANT + +#define MACROSIX(X, Y) X##Y // COMPLIANT + +#define MACROSEVEN "##'" #"#" // COMPLIANT + +#define MACROEIGHT '##' #"#" // COMPLIANT + +#define MACRONINE "##\"\"" + "#" // COMPLIANT + +#define MACROTEN "##\"\"'" + "#" // COMPLIANT + +#define MACROELEVEN(X) X #X #X // COMPLIANT + +#define MACROTWELVE(X) X##X##X // COMPLIANT + +#define MACROTHIRTEEN(X) #X##X // NON_COMPLIANT + +#define MACROFOURTEEN '#\'-#' + 1 #1 #1 + '#' // COMPLIANT \ No newline at end of file diff --git a/c/common/test/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.expected b/c/common/test/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.expected new file mode 100644 index 0000000000..7a6b7c33a5 --- /dev/null +++ b/c/common/test/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.expected @@ -0,0 +1,5 @@ +| test.c:6:7:6:8 | x1 | A named bit-field with signed integral type should have at least 2 bits of storage. | +| test.c:9:14:9:15 | x2 | A named bit-field with signed integral type should have at least 2 bits of storage. | +| test.c:11:7:11:8 | x3 | A named bit-field with signed integral type should have at least 2 bits of storage. | +| test.c:13:7:13:8 | x4 | A named bit-field with signed integral type should have at least 2 bits of storage. | +| test.c:22:14:22:14 | x | A named bit-field with signed integral type should have at least 2 bits of storage. | diff --git a/c/common/test/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.ql b/c/common/test/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.ql new file mode 100644 index 0000000000..a82fa7905a --- /dev/null +++ b/c/common/test/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.namedbitfieldswithsignedintegertype.NamedBitFieldsWithSignedIntegerType + +class TestFileQuery extends NamedBitFieldsWithSignedIntegerTypeSharedQuery, TestQuery { } diff --git a/c/common/test/rules/namedbitfieldswithsignedintegertype/test.c b/c/common/test/rules/namedbitfieldswithsignedintegertype/test.c new file mode 100644 index 0000000000..8fae6812fe --- /dev/null +++ b/c/common/test/rules/namedbitfieldswithsignedintegertype/test.c @@ -0,0 +1,28 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +#include + +struct SampleStruct { + int x1 : 1; // NON_COMPLIANT: very likely be signed, but if it's not, the + // query will automatically handle it since we use signed(), not + // isExplicitlySigned(). + signed int x2 : 1; // NON_COMPLIANT: single-bit named field with a signed type + signed char + x3 : 1; // NON_COMPLIANT: single-bit named field with a signed type + signed short + x4 : 1; // NON_COMPLIANT: single-bit named field with a signed type + unsigned int + x5 : 1; // COMPLIANT: single-bit named field but with an unsigned type + signed int x6 : 2; // COMPLIANT: named field with a signed type but declared + // to carry more than 1 bit + signed char : 1; // COMPLIANT: single-bit bit-field but unnamed +} sample_struct; + +struct S { + signed int x : 1; // NON-COMPLIANT + signed int y : 5; // COMPLIANT + signed int z : 7; // COMPLIANT + signed int : 0; // COMPLIANT + signed int : 1; // COMPLIANT + signed int : 2; // COMPLIANT +}; \ No newline at end of file diff --git a/c/common/test/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.expected b/c/common/test/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.expected new file mode 100644 index 0000000000..26401472ac --- /dev/null +++ b/c/common/test/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.expected @@ -0,0 +1,21 @@ +| test.c:37:18:37:24 | \u001aG | Invalid hexadecimal escape in string literal at '\\x1AG"'. | +| test.c:40:18:40:23 | \u00029 | Invalid octal escape in string literal at '\\029"'. | +| test.c:43:18:43:24 | \n7 | Invalid octal escape in string literal at '\\0127"'. | +| test.c:44:18:44:24 | \r7 | Invalid octal escape in string literal at '\\0157"'. | +| test.c:46:19:46:29 | \n\n9 | Invalid octal escape in string literal at '\\0129"'. | +| test.c:47:19:47:28 | \n\u00019 | Invalid octal escape in string literal at '\\019"'. | +| test.c:50:19:50:31 | \nAAA\u000f | Invalid octal escape in string literal at '\\012AAA\\017"'. | +| test.c:53:19:53:39 | Some Data \n\u000fA | Invalid octal escape in string literal at '\\017A"'. | +| test.c:54:19:55:21 | Some Data \n\u000fA5 | Invalid octal escape in string literal at '\\017A"\n "5"'. | +| test.c:56:19:58:25 | Some Data \n\u000fA\n1 | Invalid octal escape in string literal at '\\0121"'. | +| test.c:62:19:63:26 | \u0011G\u00012 | Invalid octal escape in string literal at '\\0012"'. | +| test.c:64:19:65:25 | \u0011GG\u0001 | Invalid hexadecimal escape in string literal at '\\x11G"\n "G\\001"'. | +| test.c:66:19:67:26 | \u0011GG\u00013 | Invalid hexadecimal escape in string literal at '\\x11G"\n "G\\0013"'. | +| test.c:66:19:67:26 | \u0011GG\u00013 | Invalid octal escape in string literal at '\\0013"'. | +| test.c:73:18:73:42 | Some Data \n\u000fA5 | Invalid octal escape in string literal at '\\017A" "5"'. | +| test.c:74:18:74:49 | Some Data \n\u000fA\n1 | Invalid octal escape in string literal at '\\0121"'. | +| test.c:76:18:76:32 | \u0011G\u00012 | Invalid octal escape in string literal at '\\0012"'. | +| test.c:77:18:77:32 | \u0011GG\u0001 | Invalid hexadecimal escape in string literal at '\\x11G" "G\\001"'. | +| test.c:78:18:78:33 | \u0011GG\u00013 | Invalid hexadecimal escape in string literal at '\\x11G" "G\\0013"'. | +| test.c:78:18:78:33 | \u0011GG\u00013 | Invalid octal escape in string literal at '\\0013"'. | +| test.c:81:11:81:16 | 10 | Invalid hexadecimal escape in string literal at '\\x0a''. | diff --git a/c/common/test/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.ql b/c/common/test/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.ql new file mode 100644 index 0000000000..c1aae3c31b --- /dev/null +++ b/c/common/test/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.nonterminatedescapesequences.NonTerminatedEscapeSequences + +class TestFileQuery extends NonTerminatedEscapeSequencesSharedQuery, TestQuery { } diff --git a/c/common/test/rules/nonterminatedescapesequences/test.c b/c/common/test/rules/nonterminatedescapesequences/test.c new file mode 100644 index 0000000000..67c6e3d5a3 --- /dev/null +++ b/c/common/test/rules/nonterminatedescapesequences/test.c @@ -0,0 +1,81 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +#include + +struct SampleStruct { + int x1 : 1; // NON_COMPLIANT: very likely be signed, but if it's not, the + // query will automatically handle it since we use signed(), not + // isExplicitlySigned(). + signed int x2 : 1; // NON_COMPLIANT: single-bit named field with a signed type + signed char + x3 : 1; // NON_COMPLIANT: single-bit named field with a signed type + signed short + x4 : 1; // NON_COMPLIANT: single-bit named field with a signed type + unsigned int + x5 : 1; // COMPLIANT: single-bit named field but with an unsigned type + signed int x6 : 2; // COMPLIANT: named field with a signed type but declared + // to carry more than 1 bit + signed char : 1; // COMPLIANT: single-bit bit-field but unnamed +} sample_struct; + +struct S { + signed int x : 1; // NON-COMPLIANT + signed int y : 5; // COMPLIANT + signed int z : 7; // COMPLIANT + signed int : 0; // COMPLIANT + signed int : 1; // COMPLIANT + signed int : 2; // COMPLIANT +}; +const char *a1 = "\x11" + "G"; // COMPLIANT + +const char *a2 = "\x1" + "G"; // COMPLIANT + +const char *a3 = "\x1A"; // COMPLIANT + +const char *a4 = "\x1AG"; // NON_COMPLIANT + +const char *a5 = "\021"; // COMPLIANT +const char *a6 = "\029"; // NON_COMPLIANT +const char *a7 = "\0" + "0"; // COMPLIANT +const char *a8 = "\0127"; // NON_COMPLIANT +const char *a9 = "\0157"; // NON_COMPLIANT + +const char *a10 = "\012\0129"; // NON_COMPLIANT (1x) +const char *a11 = "\012\019"; // NON_COMPLIANT +const char *a12 = "\012\017"; // COMPLIANT + +const char *a13 = "\012AAA\017"; // NON_COMPLIANT (1x) + +const char *a14 = "Some Data \012\017"; // COMPLIANT +const char *a15 = "Some Data \012\017A"; // NON_COMPLIANT (1x) +const char *a16 = "Some Data \012\017A" + "5"; // NON_COMPLIANT (1x) +const char *a17 = "Some Data \012\017" + "A" + "\0121"; // NON_COMPLIANT (1x) + +const char *a18 = "\x11" + "G\001"; // COMPLIANT +const char *a19 = "\x11" + "G\0012"; // NON_COMPLIANT (1x) +const char *a20 = "\x11G" + "G\001"; // NON_COMPLIANT (1x) +const char *a21 = "\x11G" + "G\0013"; // NON_COMPLIANT (2x) + +// clang-format off +const char *b1 = "\x11" "G"; // COMPLIANT +const char *b2 = "\x1" "G"; // COMPLIANT +const char *b3 = "\0" "0"; // COMPLIANT +const char *b4 = "Some Data \012\017A" "5"; // NON_COMPLIANT (1x) +const char *b5 = "Some Data \012\017" "A" "\0121"; // NON_COMPLIANT (1x) +const char *b6 = "\x11" "G\001"; // COMPLIANT +const char *b7 = "\x11" "G\0012"; // NON_COMPLIANT (1x) +const char *b8 = "\x11G" "G\001"; // NON_COMPLIANT (1x) +const char *b9 = "\x11G" "G\0013"; // NON_COMPLIANT (2x) + +char c1 = '\023'; // COMPLIANT +char c2 = '\x0a'; // COMPLIANT diff --git a/c/common/test/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.expected b/c/common/test/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.expected new file mode 100644 index 0000000000..65e57e3575 --- /dev/null +++ b/c/common/test/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.expected @@ -0,0 +1 @@ +| test.c:5:19:5:20 | c4 | Nonunique value of enum constant compared to $@ | test.c:5:23:5:24 | c5 | c5 | diff --git a/c/common/test/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.ql b/c/common/test/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.ql new file mode 100644 index 0000000000..97ba6f516e --- /dev/null +++ b/c/common/test/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.nonuniqueenumerationconstant.NonUniqueEnumerationConstant + +class TestFileQuery extends NonUniqueEnumerationConstantSharedQuery, TestQuery { } diff --git a/c/misra/test/rules/RULE-8-12/test.c b/c/common/test/rules/nonuniqueenumerationconstant/test.c similarity index 62% rename from c/misra/test/rules/RULE-8-12/test.c rename to c/common/test/rules/nonuniqueenumerationconstant/test.c index 349bb7867c..0712cb59e4 100644 --- a/c/misra/test/rules/RULE-8-12/test.c +++ b/c/common/test/rules/nonuniqueenumerationconstant/test.c @@ -1,3 +1,5 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. enum e { c = 3 }; // COMPLIANT enum e1 { c1 = 3, c2 }; // COMPLIANT enum e3 { c3 = 3, c4, c5 = 4 }; // NON_COMPLIANT diff --git a/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected b/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected new file mode 100644 index 0000000000..c0a8359320 --- /dev/null +++ b/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected @@ -0,0 +1,3 @@ +| test.c:9:7:9:12 | ... = ... | Use of an assignment operator's result. | +| test.c:13:11:13:16 | ... = ... | Use of an assignment operator's result. | +| test.c:15:8:15:13 | ... = ... | Use of an assignment operator's result. | diff --git a/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql b/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql new file mode 100644 index 0000000000..286e4424a4 --- /dev/null +++ b/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.resultofanassignmentoperatorshouldnotbeused.ResultOfAnAssignmentOperatorShouldNotBeUsed + +class TestFileQuery extends ResultOfAnAssignmentOperatorShouldNotBeUsedSharedQuery, TestQuery { } diff --git a/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/test.c b/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/test.c new file mode 100644 index 0000000000..db0a45384e --- /dev/null +++ b/c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/test.c @@ -0,0 +1,16 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +void test() { + int l1, l2; + int l3[1]; + + l1 = l2; // COMPLIANT + + if (l1 = 1) // NON_COMPLIANT + { + } + + l1 = l3[l2 = 0]; // NON_COMPLIANT + + l1 = l2 = 0; // NON_COMPLIANT +} diff --git a/c/common/test/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.expected b/c/common/test/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.expected new file mode 100644 index 0000000000..33ec8d6995 --- /dev/null +++ b/c/common/test/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.expected @@ -0,0 +1,4 @@ +| test.c:7:3:7:9 | ... + ... | Operation + of type unsigned int may wrap. | +| test.c:8:3:8:10 | ... += ... | Operation += of type unsigned int may wrap. | +| test.c:61:3:61:9 | ... - ... | Operation - of type unsigned int may wrap. | +| test.c:62:3:62:10 | ... -= ... | Operation -= of type unsigned int may wrap. | diff --git a/c/common/test/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.ql b/c/common/test/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.ql new file mode 100644 index 0000000000..b88e7637c1 --- /dev/null +++ b/c/common/test/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.unsignedoperationwithconstantoperandswraps.UnsignedOperationWithConstantOperandsWraps + +class TestFileQuery extends UnsignedOperationWithConstantOperandsWrapsSharedQuery, TestQuery { } diff --git a/c/common/test/rules/unsignedoperationwithconstantoperandswraps/test.c b/c/common/test/rules/unsignedoperationwithconstantoperandswraps/test.c new file mode 100644 index 0000000000..214b18a44f --- /dev/null +++ b/c/common/test/rules/unsignedoperationwithconstantoperandswraps/test.c @@ -0,0 +1,83 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. + +#include + +void test_add_simple(unsigned int i1, unsigned int i2) { + i1 + i2; // NON_COMPLIANT - not bounds checked + i1 += i2; // NON_COMPLIANT - not bounds checked +} + +void test_add_precheck(unsigned int i1, unsigned int i2) { + if (UINT_MAX - i1 < i2) { + // handle error + } else { + i1 + i2; // COMPLIANT - bounds checked + i1 += i2; // COMPLIANT - bounds checked + } +} + +void test_add_precheck_2(unsigned int i1, unsigned int i2) { + if (i1 + i2 < i1) { + // handle error + } else { + i1 + i2; // COMPLIANT - bounds checked + i1 += i2; // COMPLIANT - bounds checked + } +} + +void test_add_postcheck(unsigned int i1, unsigned int i2) { + unsigned int i3 = i1 + i2; // COMPLIANT - checked for overflow afterwards + if (i3 < i1) { + // handle error + } + i1 += i2; // COMPLIANT - checked for overflow afterwards + if (i1 < i2) { + // handle error + } +} + +void test_ex2(unsigned int i1, unsigned int i2) { + unsigned int ci1 = 2; + unsigned int ci2 = 3; + ci1 + ci2; // COMPLIANT, compile time constants + i1 + 0; // COMPLIANT + i1 += 0; // COMPLIANT + i1 - 0; // COMPLIANT + i1 -= 0; // COMPLIANT + UINT_MAX - i1; // COMPLIANT - cannot be smaller than 0 + i1 * 1; // COMPLIANT + i1 *= 1; // COMPLIANT + if (0 <= i1 && i1 < 32) { + UINT_MAX >> i1; // COMPLIANT + } +} + +void test_ex3(unsigned int i1, unsigned int i2) { + i1 << i2; // COMPLIANT - by EX3 +} + +void test_sub_simple(unsigned int i1, unsigned int i2) { + i1 - i2; // NON_COMPLIANT - not bounds checked + i1 -= i2; // NON_COMPLIANT - not bounds checked +} + +void test_sub_precheck(unsigned int i1, unsigned int i2) { + if (i1 < i2) { + // handle error + } else { + i1 - i2; // COMPLIANT - bounds checked + i1 -= i2; // COMPLIANT - bounds checked + } +} + +void test_sub_postcheck(unsigned int i1, unsigned int i2) { + unsigned int i3 = i1 - i2; // COMPLIANT - checked for wrap afterwards + if (i3 > i1) { + // handle error + } + i1 -= i2; // COMPLIANT - checked for wrap afterwards + if (i1 > i2) { + // handle error + } +} \ No newline at end of file diff --git a/c/common/test/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.expected b/c/common/test/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.expected new file mode 100644 index 0000000000..bbd4264069 --- /dev/null +++ b/c/common/test/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.expected @@ -0,0 +1,2 @@ +| test.c:5:3:5:5 | 10 | Non zero octal literal 012. | +| test.c:6:3:6:5 | 44 | Non zero octal literal 054. | diff --git a/c/common/test/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.ql b/c/common/test/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.ql new file mode 100644 index 0000000000..0404a7bc0c --- /dev/null +++ b/c/common/test/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.useofnonzerooctalliteral.UseOfNonZeroOctalLiteral + +class TestFileQuery extends UseOfNonZeroOctalLiteralSharedQuery, TestQuery { } diff --git a/c/common/test/rules/useofnonzerooctalliteral/test.c b/c/common/test/rules/useofnonzerooctalliteral/test.c new file mode 100644 index 0000000000..11b439b02e --- /dev/null +++ b/c/common/test/rules/useofnonzerooctalliteral/test.c @@ -0,0 +1,7 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +void test_non_zero_octal() { + 0; // COMPLIANT - octal literal zero permitted + 012; // NON_COMPLIANT + 054; // NON_COMPLIANT +} \ No newline at end of file diff --git a/c/misra/src/rules/DIR-4-9/FunctionOverFunctionLikeMacro.ql b/c/misra/src/rules/DIR-4-9/FunctionOverFunctionLikeMacro.ql index e53294fba5..3d8a51f219 100644 --- a/c/misra/src/rules/DIR-4-9/FunctionOverFunctionLikeMacro.ql +++ b/c/misra/src/rules/DIR-4-9/FunctionOverFunctionLikeMacro.ql @@ -15,22 +15,10 @@ import cpp import codingstandards.c.misra -import codingstandards.c.IrreplaceableFunctionLikeMacro +import codingstandards.cpp.rules.functionlikemacrosdefined.FunctionLikeMacrosDefined -predicate partOfConstantExpr(MacroInvocation i) { - exists(Expr e | - e.isConstant() and - not i.getExpr() = e and - i.getExpr().getParent+() = e - ) +class FunctionOverFunctionLikeMacroQuery extends FunctionLikeMacrosDefinedSharedQuery { + FunctionOverFunctionLikeMacroQuery() { + this = Preprocessor6Package::functionOverFunctionLikeMacroQuery() + } } - -from FunctionLikeMacro m -where - not isExcluded(m, Preprocessor6Package::functionOverFunctionLikeMacroQuery()) and - not m instanceof IrreplaceableFunctionLikeMacro and - //macros can have empty body - not m.getBody().length() = 0 and - //function call not allowed in a constant expression (where constant expr is parent) - forall(MacroInvocation i | i = m.getAnInvocation() | not partOfConstantExpr(i)) -select m, "Macro used instead of a function." diff --git a/c/misra/src/rules/RULE-13-2/UnsequencedSideEffects.ql b/c/misra/src/rules/RULE-13-2/UnsequencedSideEffects.ql index c1ac4d4b40..2497e5d4a3 100644 --- a/c/misra/src/rules/RULE-13-2/UnsequencedSideEffects.ql +++ b/c/misra/src/rules/RULE-13-2/UnsequencedSideEffects.ql @@ -13,9 +13,8 @@ import cpp import codingstandards.c.misra -import codingstandards.c.Expr -import codingstandards.c.SideEffects import codingstandards.c.Ordering +import codingstandards.c.SideEffects class VariableEffectOrAccess extends Expr { VariableEffectOrAccess() { diff --git a/c/misra/src/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql b/c/misra/src/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql index 6938f8e627..69a5d57f25 100644 --- a/c/misra/src/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql +++ b/c/misra/src/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql @@ -14,9 +14,11 @@ import cpp import codingstandards.c.misra +import codingstandards.cpp.rules.resultofanassignmentoperatorshouldnotbeused.ResultOfAnAssignmentOperatorShouldNotBeUsed -from AssignExpr e -where - not isExcluded(e, SideEffects1Package::resultOfAnAssignmentOperatorShouldNotBeUsedQuery()) and - not exists(ExprStmt s | s.getExpr() = e) -select e, "Use of an assignment operator's result." +class ResultOfAnAssignmentOperatorShouldNotBeUsedQuery extends ResultOfAnAssignmentOperatorShouldNotBeUsedSharedQuery +{ + ResultOfAnAssignmentOperatorShouldNotBeUsedQuery() { + this = SideEffects1Package::resultOfAnAssignmentOperatorShouldNotBeUsedQuery() + } +} diff --git a/c/misra/src/rules/RULE-15-1/GotoStatementUsed.ql b/c/misra/src/rules/RULE-15-1/GotoStatementUsed.ql index ddc85c305c..d1c9aadadd 100644 --- a/c/misra/src/rules/RULE-15-1/GotoStatementUsed.ql +++ b/c/misra/src/rules/RULE-15-1/GotoStatementUsed.ql @@ -13,9 +13,8 @@ import cpp import codingstandards.c.misra +import codingstandards.cpp.rules.gotostatementshouldnotbeused.GotoStatementShouldNotBeUsed -from Stmt s -where - not isExcluded(s, Statements6Package::gotoStatementUsedQuery()) and - (s instanceof GotoStmt or s instanceof ComputedGotoStmt) -select s, "Use of goto." +class GotoStatementUsedQuery extends GotoStatementShouldNotBeUsedSharedQuery { + GotoStatementUsedQuery() { this = Statements6Package::gotoStatementUsedQuery() } +} diff --git a/c/misra/src/rules/RULE-15-3/GotoLabelBlockCondition.ql b/c/misra/src/rules/RULE-15-3/GotoLabelBlockCondition.ql index aeb356b501..1f9f066f53 100644 --- a/c/misra/src/rules/RULE-15-3/GotoLabelBlockCondition.ql +++ b/c/misra/src/rules/RULE-15-3/GotoLabelBlockCondition.ql @@ -14,49 +14,8 @@ import cpp import codingstandards.c.misra +import codingstandards.cpp.rules.gotoreferencealabelinsurroundingblock.GotoReferenceALabelInSurroundingBlock -predicate isPartOfSwitch(Stmt goto) { - exists(SwitchStmt switch | switch.getStmt() = goto.getParent()) +class GotoLabelBlockConditionQuery extends GotoReferenceALabelInSurroundingBlockSharedQuery { + GotoLabelBlockConditionQuery() { this = Statements2Package::gotoLabelBlockConditionQuery() } } - -SwitchCase getSwitchCase(Stmt stmt) { - exists(int index, SwitchStmt switch | - getStmtInSwitch(switch, stmt, index) and getStmtInSwitch(switch, result, index - 1) - ) - or - exists(int index, SwitchStmt switch, Stmt other | - getStmtInSwitch(switch, stmt, index) and - getStmtInSwitch(switch, other, index - 1) and - not other instanceof SwitchCase and - result = getSwitchCase(other) - ) -} - -predicate getStmtInSwitch(SwitchStmt switch, Stmt s, int index) { - switch.getStmt().(BlockStmt).getStmt(index) = s -} - -int statementDepth(Stmt statement) { - statement.getParent() = statement.getEnclosingFunction().getBlock() and result = 1 - or - statementDepth(statement.getParent()) + 1 = result -} - -from GotoStmt goto, Stmt target, int gotoDepth, int targetDepth -where - not isExcluded(goto, Statements2Package::gotoLabelBlockConditionQuery()) and - goto.getTarget() = target and - gotoDepth = statementDepth(goto) and - targetDepth = statementDepth(target) and - targetDepth >= gotoDepth and - ( - targetDepth = gotoDepth - implies - ( - not isPartOfSwitch(goto) and not goto.getParent() = target.getParent() - or - isPartOfSwitch(goto) and not getSwitchCase(goto) = getSwitchCase(target) - ) - ) -select goto, "The $@ statement and its $@ are not declared or enclosed in the same block.", goto, - "goto", target, "label" diff --git a/c/misra/src/rules/RULE-15-6/LoopCompoundCondition.ql b/c/misra/src/rules/RULE-15-6/LoopCompoundCondition.ql index c596cb2970..a3e30ec345 100644 --- a/c/misra/src/rules/RULE-15-6/LoopCompoundCondition.ql +++ b/c/misra/src/rules/RULE-15-6/LoopCompoundCondition.ql @@ -1,6 +1,6 @@ /** * @id c/misra/loop-compound-condition - * @name RULE-15-6: the statement forming the body of a loop shall be a compound statement + * @name RULE-15-6: The statement forming the body of a loop shall be a compound statement * @description if the body of a loop is not enclosed in braces, then this can lead to incorrect * execution, and is hard for developers to maintain. * @kind problem diff --git a/c/misra/src/rules/RULE-15-6/SelectionCompoundCondition.ql b/c/misra/src/rules/RULE-15-6/SelectionCompoundCondition.ql index 0c97b3ea5a..d181ca2d1c 100644 --- a/c/misra/src/rules/RULE-15-6/SelectionCompoundCondition.ql +++ b/c/misra/src/rules/RULE-15-6/SelectionCompoundCondition.ql @@ -1,6 +1,6 @@ /** * @id c/misra/selection-compound-condition - * @name RULE-15-6: the statement forming the body of a loop shall be a compound statement + * @name RULE-15-6: The statement forming the body of a slection statement shall be a compound statement * @description if the body of a selection statement is not enclosed in braces, then this can lead * to incorrect execution, and is hard for developers to maintain. * @kind problem diff --git a/c/misra/src/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.ql b/c/misra/src/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.ql index 6ea7aa0a13..42ea398e14 100644 --- a/c/misra/src/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.ql +++ b/c/misra/src/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.ql @@ -13,14 +13,10 @@ import cpp import codingstandards.c.misra -import codingstandards.cpp.Macro +import codingstandards.cpp.rules.macroparameterfollowinghash.MacroParameterFollowingHash -from Macro m -where - not isExcluded(m, Preprocessor2Package::moreThanOneHashOperatorInMacroDefinitionQuery()) and - exists(StringizingOperator one, TokenPastingOperator two | - one.getMacro() = m and - two.getMacro() = m and - one.getOffset() < two.getOffset() - ) -select m, "Macro definition uses an # operator followed by a ## operator." +class MoreThanOneHashOperatorInMacroDefinitionQuery extends MacroParameterFollowingHashSharedQuery { + MoreThanOneHashOperatorInMacroDefinitionQuery() { + this = Preprocessor2Package::moreThanOneHashOperatorInMacroDefinitionQuery() + } +} diff --git a/c/misra/src/rules/RULE-20-12/MacroParameterUsedAsHashOperand.ql b/c/misra/src/rules/RULE-20-12/MacroParameterUsedAsHashOperand.ql index 6a66afb74b..8b9d6ca763 100644 --- a/c/misra/src/rules/RULE-20-12/MacroParameterUsedAsHashOperand.ql +++ b/c/misra/src/rules/RULE-20-12/MacroParameterUsedAsHashOperand.ql @@ -15,22 +15,11 @@ import cpp import codingstandards.c.misra -import codingstandards.cpp.Macro +import codingstandards.cpp.rules.amixedusemacroargumentsubjecttoexpansion.AMixedUseMacroArgumentSubjectToExpansion -from FunctionLikeMacro m, MacroInvocation mi, int i, string expanded, string param -where - not isExcluded(mi, Preprocessor2Package::macroParameterUsedAsHashOperandQuery()) and - mi = m.getAnInvocation() and - param = m.getParameter(i) and - ( - exists(TokenPastingOperator op | op.getMacro() = m and op.getOperand() = param) - or - exists(StringizingOperator op | op.getMacro() = m and op.getOperand() = param) - ) and - // An expansion that is equal to "" means the expansion is not used and is optimized away by EDG. This happens when the expanded argument is an operand to `#` or `##`. - // This check ensure there is an expansion that is used. - expanded = mi.getExpandedArgument(i) and - not expanded = "" and - not mi.getUnexpandedArgument(i) = mi.getExpandedArgument(i) -select m, - "Macro " + m.getName() + " contains use of parameter " + param + " used in multiple contexts." +class MacroParameterUsedAsHashOperandQuery extends AMixedUseMacroArgumentSubjectToExpansionSharedQuery +{ + MacroParameterUsedAsHashOperandQuery() { + this = Preprocessor2Package::macroParameterUsedAsHashOperandQuery() + } +} diff --git a/c/misra/src/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.ql b/c/misra/src/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.ql index f834201cbd..7263e91d53 100644 --- a/c/misra/src/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.ql +++ b/c/misra/src/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.ql @@ -13,13 +13,10 @@ import cpp import codingstandards.c.misra +import codingstandards.cpp.rules.atofatoiatolandatollused.AtofAtoiAtolAndAtollUsed -private string atoi() { result = ["atof", "atoi", "atol", "atoll"] } - -from FunctionCall fc, Function f -where - not isExcluded(fc, BannedPackage::atofAtoiAtolAndAtollOfStdlibhUsedQuery()) and - f = fc.getTarget() and - f.getName() = atoi() and - f.getFile().getBaseName() = "stdlib.h" -select fc, "Call to banned function " + f.getName() + "." +class AtofAtoiAtolAndAtollOfStdlibhUsedQuery extends AtofAtoiAtolAndAtollUsedSharedQuery { + AtofAtoiAtolAndAtollOfStdlibhUsedQuery() { + this = BannedPackage::atofAtoiAtolAndAtollOfStdlibhUsedQuery() + } +} diff --git a/c/misra/src/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.ql b/c/misra/src/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.ql index a7fdf080a7..fd77f1a688 100644 --- a/c/misra/src/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.ql +++ b/c/misra/src/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.ql @@ -15,34 +15,11 @@ import cpp import codingstandards.c.misra +import codingstandards.cpp.rules.nonterminatedescapesequences.NonTerminatedEscapeSequences -bindingset[s] -predicate isOctalEscape(string s) { - s.charAt(0) = "\\" and - exists(int i | i = [0 .. 7] | i.toString() = s.charAt(1)) +class OctalAndHexadecimalEscapeSequencesNotTerminatedQuery extends NonTerminatedEscapeSequencesSharedQuery +{ + OctalAndHexadecimalEscapeSequencesNotTerminatedQuery() { + this = SyntaxPackage::octalAndHexadecimalEscapeSequencesNotTerminatedQuery() + } } - -bindingset[s] -predicate isHexEscape(string s) { s.indexOf("\\x") = 0 } - -from Literal l, string escapeKind, string s -where - not isExcluded(l, SyntaxPackage::octalAndHexadecimalEscapeSequencesNotTerminatedQuery()) and - exists(int idx, string sl | - sl = l.getValueText() and - idx = sl.indexOf("\\") and - s = sl.substring(idx, sl.length()) and - // Note: Octal representations must be 1-3 digits. There is no limitation on a - // Hex literal as long as the characters are valid. This query does not consider - // if the hex literal being constructed will overflow. - ( - isHexEscape(s) and - not s.regexpMatch("^((\\\\x[0-9A-F]+(?=[\"'\\\\])))[\\s\\S]*") and - escapeKind = "hexadecimal" - or - isOctalEscape(s) and - not s.regexpMatch("^(((\\\\[0-7]{1,3})(?=[\"'\\\\])))[\\s\\S]*") and - escapeKind = "octal" - ) - ) -select l, "Invalid " + escapeKind + " escape in string literal at '" + s + "'." diff --git a/c/misra/src/rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.ql b/c/misra/src/rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.ql index fce1d9ad1a..f5bc589a4d 100644 --- a/c/misra/src/rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.ql +++ b/c/misra/src/rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.ql @@ -12,33 +12,11 @@ import cpp import codingstandards.c.misra -import codingstandards.cpp.Compiler +import codingstandards.cpp.rules.bitfieldshallhaveanappropriatetype.BitFieldShallHaveAnAppropriateType -Type getSupportedBitFieldType(Compiler compiler) { - compiler instanceof UnsupportedCompiler and - ( - result instanceof IntType and - ( - result.(IntegralType).isExplicitlySigned() or - result.(IntegralType).isExplicitlyUnsigned() - ) - or - result instanceof BoolType - ) - or - (compiler instanceof Gcc or compiler instanceof Clang) and - ( - result instanceof IntegralOrEnumType - or - result instanceof BoolType - ) +class BitFieldsShallOnlyBeDeclaredWithAnAppropriateTypeQuery extends BitFieldShallHaveAnAppropriateTypeSharedQuery +{ + BitFieldsShallOnlyBeDeclaredWithAnAppropriateTypeQuery() { + this = BitfieldTypesPackage::bitFieldsShallOnlyBeDeclaredWithAnAppropriateTypeQuery() + } } - -from BitField bitField -where - not isExcluded(bitField, - BitfieldTypesPackage::bitFieldsShallOnlyBeDeclaredWithAnAppropriateTypeQuery()) and - /* A violation would neither be an appropriate primitive type nor an appropriate typedef. */ - not getSupportedBitFieldType(getCompiler(bitField.getFile())) = - bitField.getType().resolveTypedefs() -select bitField, "Bit-field '" + bitField + "' is declared on type '" + bitField.getType() + "'." diff --git a/c/misra/src/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.ql b/c/misra/src/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.ql index d4be3d6dd2..d699c1c9b7 100644 --- a/c/misra/src/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.ql +++ b/c/misra/src/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.ql @@ -12,23 +12,11 @@ import cpp import codingstandards.c.misra +import codingstandards.cpp.rules.namedbitfieldswithsignedintegertype.NamedBitFieldsWithSignedIntegerType -/* - * Check if the DECLARED bit-fields is a single bit, because Rule 6.2 also intends to catch confusion on the programmers' part. Consider: - * - * struct S { - * int32_t x: 1; - * } - * - * In this case, field x is essentially of 32 bits, but is declared as 1 bit and its type int32_t is signed. Therefore, it indicates confusion by the programmer, which is exactly what this rule intends to find. - */ - -from BitField bitField -where - not isExcluded(bitField, BitfieldTypesPackage::singleBitNamedBitFieldsOfASignedTypeQuery()) and - bitField.getDeclaredNumBits() = 1 and // Single-bit, - not bitField.isAnonymous() and // named, - bitField.getType().(IntegralType).isSigned() // but its type is signed. -select bitField, - "Single-bit bit-field named " + bitField.toString() + " has a signed type " + bitField.getType() + - "." +class SingleBitNamedBitFieldsOfASignedTypeQuery extends NamedBitFieldsWithSignedIntegerTypeSharedQuery +{ + SingleBitNamedBitFieldsOfASignedTypeQuery() { + this = BitfieldTypesPackage::singleBitNamedBitFieldsOfASignedTypeQuery() + } +} diff --git a/c/misra/src/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.ql b/c/misra/src/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.ql index 4fc257578b..85c14ff419 100644 --- a/c/misra/src/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.ql +++ b/c/misra/src/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.ql @@ -14,7 +14,7 @@ import cpp import codingstandards.c.misra -import codingstandards.c.Literals +import codingstandards.cpp.Literals from IntegerLiteral l where diff --git a/c/misra/src/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.ql b/c/misra/src/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.ql index 0772da9b05..a4fcb0e4f3 100644 --- a/c/misra/src/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.ql +++ b/c/misra/src/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.ql @@ -14,25 +14,11 @@ import cpp import codingstandards.c.misra +import codingstandards.cpp.rules.nonuniqueenumerationconstant.NonUniqueEnumerationConstant -/** - * An `EnumConstant` that has an implicitly specified value: - * `enum e { explicit = 1, implicit }` - */ -class ImplicitlySpecifiedEnumConstant extends EnumConstant { - ImplicitlySpecifiedEnumConstant() { - //implicitly specified have an initializer with location: `file://:0:0:0:0` - not this.getInitializer().getLocation().getFile() = this.getFile() +class ValueImplicitEnumerationConstantNotUniqueQuery extends NonUniqueEnumerationConstantSharedQuery +{ + ValueImplicitEnumerationConstantNotUniqueQuery() { + this = Declarations7Package::valueImplicitEnumerationConstantNotUniqueQuery() } } - -from EnumConstant exp, ImplicitlySpecifiedEnumConstant imp -where - not isExcluded(exp, Declarations7Package::valueImplicitEnumerationConstantNotUniqueQuery()) and - not isExcluded(imp, Declarations7Package::valueImplicitEnumerationConstantNotUniqueQuery()) and - not exp = imp and - imp.getValue() = exp.getValue() and - imp.getDeclaringEnum() = exp.getDeclaringEnum() and - //can technically be the same declared enum across multiple headers but those are not relevant to this rule - imp.getFile() = exp.getFile() -select imp, "Nonunique value of enum constant compared to $@", exp, exp.getName() diff --git a/c/misra/test/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.testref b/c/misra/test/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.testref index ea9ce384ea..3b0dc2fe5a 100644 --- a/c/misra/test/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.testref +++ b/c/misra/test/rules/DIR-4-2/UsageOfAssemblyLanguageShouldBeDocumented.testref @@ -1 +1 @@ -cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql \ No newline at end of file +c/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql \ No newline at end of file diff --git a/c/misra/test/rules/DIR-4-4/SectionsOfCodeShallNotBeCommentedOut.testref b/c/misra/test/rules/DIR-4-4/SectionsOfCodeShallNotBeCommentedOut.testref index 303a38a19b..4460b5ed53 100644 --- a/c/misra/test/rules/DIR-4-4/SectionsOfCodeShallNotBeCommentedOut.testref +++ b/c/misra/test/rules/DIR-4-4/SectionsOfCodeShallNotBeCommentedOut.testref @@ -1 +1 @@ -cpp/common/test/rules/sectionsofcodeshallnotbecommentedout/SectionsOfCodeShallNotBeCommentedOut.ql \ No newline at end of file +c/common/test/rules/sectionsofcodeshallnotbecommentedout/SectionsOfCodeShallNotBeCommentedOut.ql \ No newline at end of file diff --git a/c/misra/test/rules/DIR-4-5/IdentifiersInTheSameNameSpaceUnambiguous.testref b/c/misra/test/rules/DIR-4-5/IdentifiersInTheSameNameSpaceUnambiguous.testref index dffdbb26b8..2dc788dd11 100644 --- a/c/misra/test/rules/DIR-4-5/IdentifiersInTheSameNameSpaceUnambiguous.testref +++ b/c/misra/test/rules/DIR-4-5/IdentifiersInTheSameNameSpaceUnambiguous.testref @@ -1 +1 @@ -cpp/common/test/rules/differentidentifiersnottypographicallyunambiguous/DifferentIdentifiersNotTypographicallyUnambiguous.ql \ No newline at end of file +c/common/test/rules/differentidentifiersnottypographicallyunambiguous/DifferentIdentifiersNotTypographicallyUnambiguous.ql \ No newline at end of file diff --git a/c/misra/test/rules/DIR-4-9/FunctionOverFunctionLikeMacro.testref b/c/misra/test/rules/DIR-4-9/FunctionOverFunctionLikeMacro.testref new file mode 100644 index 0000000000..fb033c44e4 --- /dev/null +++ b/c/misra/test/rules/DIR-4-9/FunctionOverFunctionLikeMacro.testref @@ -0,0 +1 @@ +c/common/test/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-13-2/UnsequencedSideEffects.expected b/c/misra/test/rules/RULE-13-2/UnsequencedSideEffects.expected index 17b89c2f01..75bd8169ba 100644 --- a/c/misra/test/rules/RULE-13-2/UnsequencedSideEffects.expected +++ b/c/misra/test/rules/RULE-13-2/UnsequencedSideEffects.expected @@ -3,4 +3,4 @@ | test.c:17:3:17:21 | ... = ... | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:17:8:17:9 | l1 | side effect | test.c:17:8:17:9 | l1 | l1 | test.c:17:13:17:14 | l1 | side effect | test.c:17:13:17:14 | l1 | l1 | | test.c:19:3:19:5 | call to foo | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:19:7:19:8 | l1 | side effect | test.c:19:7:19:8 | l1 | l1 | test.c:19:11:19:12 | l2 | side effect | test.c:19:11:19:12 | l2 | l2 | | test.c:25:3:25:5 | call to foo | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:25:7:25:10 | ... ++ | side effect | test.c:25:7:25:8 | l8 | l8 | test.c:25:13:25:14 | l8 | read | test.c:25:13:25:14 | l8 | l8 | -| test.c:35:5:35:13 | ... = ... | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:35:10:35:12 | ... ++ | side effect | test.c:35:10:35:10 | i | i | test.c:35:10:35:12 | ... ++ | side effect | test.c:35:10:35:10 | i | i | +| test.c:35:5:35:13 | ... = ... | The expression contains unsequenced $@ to $@ and $@ to $@. | test.c:35:10:35:12 | ... ++ | side effect | test.c:35:10:35:10 | i | i | test.c:35:10:35:12 | ... ++ | side effect | test.c:35:10:35:10 | i | i | \ No newline at end of file diff --git a/c/misra/test/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected b/c/misra/test/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected deleted file mode 100644 index 57f90043e1..0000000000 --- a/c/misra/test/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected +++ /dev/null @@ -1,3 +0,0 @@ -| test.c:7:7:7:12 | ... = ... | Use of an assignment operator's result. | -| test.c:11:11:11:16 | ... = ... | Use of an assignment operator's result. | -| test.c:13:8:13:13 | ... = ... | Use of an assignment operator's result. | diff --git a/c/misra/test/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.qlref b/c/misra/test/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.qlref deleted file mode 100644 index 16d027d915..0000000000 --- a/c/misra/test/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.testref b/c/misra/test/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.testref new file mode 100644 index 0000000000..41e225624c --- /dev/null +++ b/c/misra/test/rules/RULE-13-4/ResultOfAnAssignmentOperatorShouldNotBeUsed.testref @@ -0,0 +1 @@ +c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-15-1/GotoStatementUsed.expected b/c/misra/test/rules/RULE-15-1/GotoStatementUsed.expected deleted file mode 100644 index 7e06759159..0000000000 --- a/c/misra/test/rules/RULE-15-1/GotoStatementUsed.expected +++ /dev/null @@ -1 +0,0 @@ -| test.c:4:3:4:14 | goto ... | Use of goto. | diff --git a/c/misra/test/rules/RULE-15-1/GotoStatementUsed.qlref b/c/misra/test/rules/RULE-15-1/GotoStatementUsed.qlref deleted file mode 100644 index 338455d28f..0000000000 --- a/c/misra/test/rules/RULE-15-1/GotoStatementUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-15-1/GotoStatementUsed.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-15-1/GotoStatementUsed.testref b/c/misra/test/rules/RULE-15-1/GotoStatementUsed.testref new file mode 100644 index 0000000000..1834c6e140 --- /dev/null +++ b/c/misra/test/rules/RULE-15-1/GotoStatementUsed.testref @@ -0,0 +1 @@ +c/common/test/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-15-1/test.c b/c/misra/test/rules/RULE-15-1/test.c deleted file mode 100644 index d13f01961c..0000000000 --- a/c/misra/test/rules/RULE-15-1/test.c +++ /dev/null @@ -1,9 +0,0 @@ -void test_goto() { - int x = 1; - - goto label1; // NON_COMPLIANT - -label1: - - x = 2; -} \ No newline at end of file diff --git a/c/misra/test/rules/RULE-15-3/GotoLabelBlockCondition.expected b/c/misra/test/rules/RULE-15-3/GotoLabelBlockCondition.expected deleted file mode 100644 index 730403cbd7..0000000000 --- a/c/misra/test/rules/RULE-15-3/GotoLabelBlockCondition.expected +++ /dev/null @@ -1,3 +0,0 @@ -| test.c:2:3:2:10 | goto ... | The $@ statement and its $@ are not declared or enclosed in the same block. | test.c:2:3:2:10 | goto ... | goto | test.c:4:3:4:5 | label ...: | label | -| test.c:40:3:40:10 | goto ... | The $@ statement and its $@ are not declared or enclosed in the same block. | test.c:40:3:40:10 | goto ... | goto | test.c:44:3:44:5 | label ...: | label | -| test.c:55:5:55:12 | goto ... | The $@ statement and its $@ are not declared or enclosed in the same block. | test.c:55:5:55:12 | goto ... | goto | test.c:58:3:58:5 | label ...: | label | diff --git a/c/misra/test/rules/RULE-15-3/GotoLabelBlockCondition.qlref b/c/misra/test/rules/RULE-15-3/GotoLabelBlockCondition.qlref deleted file mode 100644 index 5f430f0790..0000000000 --- a/c/misra/test/rules/RULE-15-3/GotoLabelBlockCondition.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-15-3/GotoLabelBlockCondition.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-15-3/GotoLabelBlockCondition.testref b/c/misra/test/rules/RULE-15-3/GotoLabelBlockCondition.testref new file mode 100644 index 0000000000..cf558d9350 --- /dev/null +++ b/c/misra/test/rules/RULE-15-3/GotoLabelBlockCondition.testref @@ -0,0 +1 @@ +c/common/test/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.expected b/c/misra/test/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.expected deleted file mode 100644 index 406010428c..0000000000 --- a/c/misra/test/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.expected +++ /dev/null @@ -1 +0,0 @@ -| test.c:25:1:25:29 | #define MACROTHIRTEEN(X) #X ## X | Macro definition uses an # operator followed by a ## operator. | diff --git a/c/misra/test/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.qlref b/c/misra/test/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.qlref deleted file mode 100644 index 35ef457cac..0000000000 --- a/c/misra/test/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.testref b/c/misra/test/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.testref new file mode 100644 index 0000000000..be7ebf2815 --- /dev/null +++ b/c/misra/test/rules/RULE-20-11/MoreThanOneHashOperatorInMacroDefinition.testref @@ -0,0 +1 @@ +c/common/test/rules/macroparameterfollowinghash/MacroParameterFollowingHash.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-20-12/MacroParameterUsedAsHashOperand.qlref b/c/misra/test/rules/RULE-20-12/MacroParameterUsedAsHashOperand.qlref deleted file mode 100644 index a2edc3acc4..0000000000 --- a/c/misra/test/rules/RULE-20-12/MacroParameterUsedAsHashOperand.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-20-12/MacroParameterUsedAsHashOperand.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-20-12/MacroParameterUsedAsHashOperand.testref b/c/misra/test/rules/RULE-20-12/MacroParameterUsedAsHashOperand.testref new file mode 100644 index 0000000000..d1cc5971c7 --- /dev/null +++ b/c/misra/test/rules/RULE-20-12/MacroParameterUsedAsHashOperand.testref @@ -0,0 +1 @@ +c/common/test/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.expected b/c/misra/test/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.expected deleted file mode 100644 index 29a0c6fac1..0000000000 --- a/c/misra/test/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.expected +++ /dev/null @@ -1,4 +0,0 @@ -| test.c:6:14:6:17 | call to atof | Call to banned function atof. | -| test.c:7:12:7:15 | call to atoi | Call to banned function atoi. | -| test.c:8:13:8:16 | call to atol | Call to banned function atol. | -| test.c:9:18:9:22 | call to atoll | Call to banned function atoll. | diff --git a/c/misra/test/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.qlref b/c/misra/test/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.qlref deleted file mode 100644 index 52e70db92b..0000000000 --- a/c/misra/test/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.testref b/c/misra/test/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.testref new file mode 100644 index 0000000000..fccafa2049 --- /dev/null +++ b/c/misra/test/rules/RULE-21-7/AtofAtoiAtolAndAtollOfStdlibhUsed.testref @@ -0,0 +1 @@ +c/common/test/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.expected b/c/misra/test/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.expected deleted file mode 100644 index 39d5aa5d85..0000000000 --- a/c/misra/test/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.expected +++ /dev/null @@ -1,21 +0,0 @@ -| test.c:9:18:9:24 | \u001aG | Invalid hexadecimal escape in string literal at '\\x1AG"'. | -| test.c:12:18:12:23 | \u00029 | Invalid octal escape in string literal at '\\029"'. | -| test.c:15:18:15:24 | \n7 | Invalid octal escape in string literal at '\\0127"'. | -| test.c:16:18:16:24 | \r7 | Invalid octal escape in string literal at '\\0157"'. | -| test.c:18:19:18:29 | \n\n9 | Invalid octal escape in string literal at '\\0129"'. | -| test.c:19:19:19:28 | \n\u00019 | Invalid octal escape in string literal at '\\019"'. | -| test.c:22:19:22:31 | \nAAA\u000f | Invalid octal escape in string literal at '\\012AAA\\017"'. | -| test.c:25:19:25:39 | Some Data \n\u000fA | Invalid octal escape in string literal at '\\017A"'. | -| test.c:26:19:27:21 | Some Data \n\u000fA5 | Invalid octal escape in string literal at '\\017A"\n "5"'. | -| test.c:28:19:30:25 | Some Data \n\u000fA\n1 | Invalid octal escape in string literal at '\\0121"'. | -| test.c:34:19:35:26 | \u0011G\u00012 | Invalid octal escape in string literal at '\\0012"'. | -| test.c:36:19:37:25 | \u0011GG\u0001 | Invalid hexadecimal escape in string literal at '\\x11G"\n "G\\001"'. | -| test.c:38:19:39:26 | \u0011GG\u00013 | Invalid hexadecimal escape in string literal at '\\x11G"\n "G\\0013"'. | -| test.c:38:19:39:26 | \u0011GG\u00013 | Invalid octal escape in string literal at '\\0013"'. | -| test.c:45:18:45:42 | Some Data \n\u000fA5 | Invalid octal escape in string literal at '\\017A" "5"'. | -| test.c:46:18:46:49 | Some Data \n\u000fA\n1 | Invalid octal escape in string literal at '\\0121"'. | -| test.c:48:18:48:32 | \u0011G\u00012 | Invalid octal escape in string literal at '\\0012"'. | -| test.c:49:18:49:32 | \u0011GG\u0001 | Invalid hexadecimal escape in string literal at '\\x11G" "G\\001"'. | -| test.c:50:18:50:33 | \u0011GG\u00013 | Invalid hexadecimal escape in string literal at '\\x11G" "G\\0013"'. | -| test.c:50:18:50:33 | \u0011GG\u00013 | Invalid octal escape in string literal at '\\0013"'. | -| test.c:53:11:53:16 | 10 | Invalid hexadecimal escape in string literal at '\\x0a''. | diff --git a/c/misra/test/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.qlref b/c/misra/test/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.qlref deleted file mode 100644 index fbdd187532..0000000000 --- a/c/misra/test/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.testref b/c/misra/test/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.testref new file mode 100644 index 0000000000..f8b5396a9c --- /dev/null +++ b/c/misra/test/rules/RULE-4-1/OctalAndHexadecimalEscapeSequencesNotTerminated.testref @@ -0,0 +1 @@ +c/common/test/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.testref b/c/misra/test/rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.testref new file mode 100644 index 0000000000..9d02a25700 --- /dev/null +++ b/c/misra/test/rules/RULE-6-1/BitFieldsShallOnlyBeDeclaredWithAnAppropriateType.testref @@ -0,0 +1 @@ +c/common/test/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.expected b/c/misra/test/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.expected deleted file mode 100644 index df7677961a..0000000000 --- a/c/misra/test/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.expected +++ /dev/null @@ -1,4 +0,0 @@ -| test.c:4:7:4:8 | x1 | Single-bit bit-field named x1 has a signed type int. | -| test.c:7:14:7:15 | x2 | Single-bit bit-field named x2 has a signed type signed int. | -| test.c:9:7:9:8 | x3 | Single-bit bit-field named x3 has a signed type signed char. | -| test.c:11:7:11:8 | x4 | Single-bit bit-field named x4 has a signed type signed short. | diff --git a/c/misra/test/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.qlref b/c/misra/test/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.qlref deleted file mode 100644 index 50c34f70a7..0000000000 --- a/c/misra/test/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.testref b/c/misra/test/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.testref new file mode 100644 index 0000000000..edc2f5a16d --- /dev/null +++ b/c/misra/test/rules/RULE-6-2/SingleBitNamedBitFieldsOfASignedType.testref @@ -0,0 +1 @@ +c/common/test/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-7-1/OctalConstantsUsed.expected b/c/misra/test/rules/RULE-7-1/OctalConstantsUsed.expected deleted file mode 100644 index deecdf994c..0000000000 --- a/c/misra/test/rules/RULE-7-1/OctalConstantsUsed.expected +++ /dev/null @@ -1,2 +0,0 @@ -| test.c:7:3:7:5 | 10 | Use of banned $@ constant. | test.c:7:3:7:5 | 10 | octal | -| test.c:8:3:8:5 | 44 | Use of banned $@ constant. | test.c:8:3:8:5 | 44 | octal | diff --git a/c/misra/test/rules/RULE-7-1/OctalConstantsUsed.qlref b/c/misra/test/rules/RULE-7-1/OctalConstantsUsed.qlref deleted file mode 100644 index 7d66675dad..0000000000 --- a/c/misra/test/rules/RULE-7-1/OctalConstantsUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-7-1/OctalConstantsUsed.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-7-1/test.c b/c/misra/test/rules/RULE-7-1/test.c deleted file mode 100644 index fb0f2e0d36..0000000000 --- a/c/misra/test/rules/RULE-7-1/test.c +++ /dev/null @@ -1,10 +0,0 @@ -void test_non_zero_octal() { - '\0'; // COMPLIANT - octal zero escape sequence permitted - '\012'; // COMPLIANT - '\054'; // COMPLIANT - '\0149'; // COMPLIANT - 0; // COMPLIANT - octal literal zero permitted - 012; // NON_COMPLIANT - 054; // NON_COMPLIANT - "\0"; // COMPLIANT - octal zero escape sequence permitted -} diff --git a/c/misra/test/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.expected b/c/misra/test/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.expected deleted file mode 100644 index 279fd7e621..0000000000 --- a/c/misra/test/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.expected +++ /dev/null @@ -1,16 +0,0 @@ -| test.c:3:10:3:11 | 0 | Lowercase 'l' used as a literal suffix. | -| test.c:4:10:4:12 | 0 | Lowercase 'l' used as a literal suffix. | -| test.c:7:10:7:12 | 0 | Lowercase 'l' used as a literal suffix. | -| test.c:8:10:8:12 | 0 | Lowercase 'l' used as a literal suffix. | -| test.c:13:11:13:12 | 0 | Lowercase 'l' used as a literal suffix. | -| test.c:14:11:14:13 | 0 | Lowercase 'l' used as a literal suffix. | -| test.c:17:11:17:13 | 0 | Lowercase 'l' used as a literal suffix. | -| test.c:18:11:18:13 | 0 | Lowercase 'l' used as a literal suffix. | -| test.c:23:10:23:14 | 1 | Lowercase 'l' used as a literal suffix. | -| test.c:24:10:24:15 | 1 | Lowercase 'l' used as a literal suffix. | -| test.c:27:10:27:15 | 1 | Lowercase 'l' used as a literal suffix. | -| test.c:28:10:28:15 | 1 | Lowercase 'l' used as a literal suffix. | -| test.c:33:11:33:14 | 1 | Lowercase 'l' used as a literal suffix. | -| test.c:34:11:34:15 | 1 | Lowercase 'l' used as a literal suffix. | -| test.c:37:11:37:15 | 1 | Lowercase 'l' used as a literal suffix. | -| test.c:38:11:38:15 | 1 | Lowercase 'l' used as a literal suffix. | diff --git a/c/misra/test/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.qlref b/c/misra/test/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.qlref deleted file mode 100644 index 464efc3b2f..0000000000 --- a/c/misra/test/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.testref b/c/misra/test/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.testref new file mode 100644 index 0000000000..1fc7164d80 --- /dev/null +++ b/c/misra/test/rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.testref @@ -0,0 +1 @@ +c/common/test/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-7-3/cpp/LowercaseCharacterLUsedInLiteralSuffix.expected b/c/misra/test/rules/RULE-7-3/cpp/LowercaseCharacterLUsedInLiteralSuffix.expected deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/c/misra/test/rules/RULE-7-3/cpp/LowercaseCharacterLUsedInLiteralSuffix.qlref b/c/misra/test/rules/RULE-7-3/cpp/LowercaseCharacterLUsedInLiteralSuffix.qlref deleted file mode 100644 index 464efc3b2f..0000000000 --- a/c/misra/test/rules/RULE-7-3/cpp/LowercaseCharacterLUsedInLiteralSuffix.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-7-3/LowercaseCharacterLUsedInLiteralSuffix.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-7-3/cpp/options b/c/misra/test/rules/RULE-7-3/cpp/options deleted file mode 100644 index 8dbed822c6..0000000000 --- a/c/misra/test/rules/RULE-7-3/cpp/options +++ /dev/null @@ -1 +0,0 @@ -semmle-extractor-options:--clang -std=c++14 --edg --diag_error=implicit_func_decl -nostdinc -I../../../../../cpp/common/test/includes/standard-library \ No newline at end of file diff --git a/c/misra/test/rules/RULE-7-3/cpp/test.cpp b/c/misra/test/rules/RULE-7-3/cpp/test.cpp deleted file mode 100644 index ba3ca4f14e..0000000000 --- a/c/misra/test/rules/RULE-7-3/cpp/test.cpp +++ /dev/null @@ -1 +0,0 @@ -int x = false; // COMPLIANT - reported as FP in #319 \ No newline at end of file diff --git a/c/misra/test/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.expected b/c/misra/test/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.expected deleted file mode 100644 index 55abb72b57..0000000000 --- a/c/misra/test/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.expected +++ /dev/null @@ -1 +0,0 @@ -| test.c:3:19:3:20 | c4 | Nonunique value of enum constant compared to $@ | test.c:3:23:3:24 | c5 | c5 | diff --git a/c/misra/test/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.qlref b/c/misra/test/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.qlref deleted file mode 100644 index e43c765d37..0000000000 --- a/c/misra/test/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.testref b/c/misra/test/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.testref new file mode 100644 index 0000000000..7db7d79d72 --- /dev/null +++ b/c/misra/test/rules/RULE-8-12/ValueImplicitEnumerationConstantNotUnique.testref @@ -0,0 +1 @@ +c/common/test/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.ql \ No newline at end of file diff --git a/cpp/autosar/src/rules/A12-1-1/ExplicitConstructorBaseClassInitialization.ql b/cpp/autosar/src/rules/A12-1-1/ExplicitConstructorBaseClassInitialization.ql index e1aeec46a0..66fe0345dc 100644 --- a/cpp/autosar/src/rules/A12-1-1/ExplicitConstructorBaseClassInitialization.ql +++ b/cpp/autosar/src/rules/A12-1-1/ExplicitConstructorBaseClassInitialization.ql @@ -16,29 +16,11 @@ import cpp import codingstandards.cpp.autosar -import codingstandards.cpp.Constructor +import codingstandards.cpp.rules.initializeallvirtualbaseclasses.InitializeAllVirtualBaseClasses -from Constructor c, Class declaringType, Class baseClass, string type -where - not isExcluded(c, InitializationPackage::explicitConstructorBaseClassInitializationQuery()) and - declaringType = c.getDeclaringType() and - ( - declaringType.getABaseClass() = baseClass and type = "" - or - baseClass.(VirtualBaseClass).getAVirtuallyDerivedClass().getADerivedClass+() = declaringType and - type = " virtual" - ) and - // There is not an initializer on the constructor for this particular base class - not exists(ConstructorBaseClassInit init | - c.getAnInitializer() = init and - init.getInitializedClass() = baseClass and - not init.isCompilerGenerated() - ) and - // Must be a defined constructor - c.hasDefinition() and - // Not a compiler-generated constructor - not c.isCompilerGenerated() and - // Not a defaulted constructor - not c.isDefaulted() -select c, "Constructor for $@ does not explicitly call constructor for" + type + " base class $@.", - declaringType, declaringType.getSimpleName(), baseClass, baseClass.getSimpleName() +class ExplicitConstructorBaseClassInitializationQuery extends InitializeAllVirtualBaseClassesSharedQuery +{ + ExplicitConstructorBaseClassInitializationQuery() { + this = InitializationPackage::explicitConstructorBaseClassInitializationQuery() + } +} diff --git a/cpp/autosar/src/rules/A12-8-5/CopyAssignmentAndAMoveHandleSelfAssignment.ql b/cpp/autosar/src/rules/A12-8-5/CopyAssignmentAndAMoveHandleSelfAssignment.ql index a2ce643784..9697176711 100644 --- a/cpp/autosar/src/rules/A12-8-5/CopyAssignmentAndAMoveHandleSelfAssignment.ql +++ b/cpp/autosar/src/rules/A12-8-5/CopyAssignmentAndAMoveHandleSelfAssignment.ql @@ -17,43 +17,11 @@ import cpp import codingstandards.cpp.autosar -import codingstandards.cpp.Operator +import codingstandards.cpp.rules.copyandmoveassignmentsshallhandleselfassignment.CopyAndMoveAssignmentsShallHandleSelfAssignment -predicate isUserCopyOrUserMove(Operator o) { - o instanceof UserCopyOperator or - o instanceof UserMoveOperator +class CopyAssignmentAndAMoveHandleSelfAssignmentQuery extends CopyAndMoveAssignmentsShallHandleSelfAssignmentSharedQuery +{ + CopyAssignmentAndAMoveHandleSelfAssignmentQuery() { + this = OperatorInvariantsPackage::copyAssignmentAndAMoveHandleSelfAssignmentQuery() + } } - -predicate callsStdSwap(Function f) { - exists(FunctionCall fc | - fc.getTarget().hasGlobalOrStdName("swap") and - fc.getEnclosingFunction() = f - ) -} - -predicate callsNoExceptSwap(Operator o) { - exists(Function f, FunctionCall fc | - callsStdSwap(f) and - fc.getEnclosingFunction() = o and - fc.getTarget() = f - ) -} - -predicate checksForSelfAssignment(Operator o) { - exists(IfStmt i, ComparisonOperation c | - i.getEnclosingFunction() = o and - i.getCondition() = c and - ( - c.getLeftOperand().toString() = "this" or - c.getRightOperand().toString() = "this" - ) - ) -} - -from Operator o -where - not isExcluded(o, OperatorInvariantsPackage::copyAssignmentAndAMoveHandleSelfAssignmentQuery()) and - isUserCopyOrUserMove(o) and - not callsNoExceptSwap(o) and - not checksForSelfAssignment(o) -select o, "User defined copy or user defined move does not handle self-assignment correctly." diff --git a/cpp/autosar/src/rules/A14-8-2/ExplicitSpecializationsOfFunctionTemplatesUsed.ql b/cpp/autosar/src/rules/A14-8-2/ExplicitSpecializationsOfFunctionTemplatesUsed.ql index e53b532493..86218a47d6 100644 --- a/cpp/autosar/src/rules/A14-8-2/ExplicitSpecializationsOfFunctionTemplatesUsed.ql +++ b/cpp/autosar/src/rules/A14-8-2/ExplicitSpecializationsOfFunctionTemplatesUsed.ql @@ -16,8 +16,11 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.functiontemplatesexplicitlyspecialized.FunctionTemplatesExplicitlySpecialized -from FunctionTemplateSpecialization f -where not isExcluded(f, TemplatesPackage::explicitSpecializationsOfFunctionTemplatesUsedQuery()) -select f, "Specialization of function template from primary template located in $@.", - f.getPrimaryTemplate(), f.getPrimaryTemplate().getFile().getBaseName() +class ExplicitSpecializationsOfFunctionTemplatesUsedQuery extends FunctionTemplatesExplicitlySpecializedSharedQuery +{ + ExplicitSpecializationsOfFunctionTemplatesUsedQuery() { + this = TemplatesPackage::explicitSpecializationsOfFunctionTemplatesUsedQuery() + } +} diff --git a/cpp/autosar/src/rules/A15-1-2/PointerExceptionObject.ql b/cpp/autosar/src/rules/A15-1-2/PointerExceptionObject.ql index 348e02609c..b2f101082f 100644 --- a/cpp/autosar/src/rules/A15-1-2/PointerExceptionObject.ql +++ b/cpp/autosar/src/rules/A15-1-2/PointerExceptionObject.ql @@ -15,10 +15,8 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.exceptionobjecthavepointertype.ExceptionObjectHavePointerType -from Expr thrownExpr -where - not isExcluded(thrownExpr, Exceptions1Package::pointerExceptionObjectQuery()) and - thrownExpr = any(ThrowExpr te).getExpr() and - thrownExpr.getType().getUnspecifiedType() instanceof PointerType -select thrownExpr, "Exception object with pointer type " + thrownExpr.getType() + " is thrown here." +class PointerExceptionObjectQuery extends ExceptionObjectHavePointerTypeSharedQuery { + PointerExceptionObjectQuery() { this = Exceptions1Package::pointerExceptionObjectQuery() } +} diff --git a/cpp/autosar/src/rules/A15-4-2/NoExceptFunctionThrows.ql b/cpp/autosar/src/rules/A15-4-2/NoExceptFunctionThrows.ql index 0c5bbb6011..169b5fc8f3 100644 --- a/cpp/autosar/src/rules/A15-4-2/NoExceptFunctionThrows.ql +++ b/cpp/autosar/src/rules/A15-4-2/NoExceptFunctionThrows.ql @@ -15,25 +15,8 @@ import cpp import codingstandards.cpp.autosar -import codingstandards.cpp.exceptions.ExceptionFlow -import ExceptionPathGraph -import codingstandards.cpp.exceptions.ExceptionSpecifications +import codingstandards.cpp.rules.noexceptfunctionshouldnotpropagatetothecaller.NoexceptFunctionShouldNotPropagateToTheCaller -class NoExceptThrowingFunction extends ExceptionThrowingFunction { - NoExceptThrowingFunction() { - // Can exit with an exception - exists(getAFunctionThrownType(_, _)) and - // But is marked noexcept(true) or equivalent - isNoExceptTrue(this) - } +class NoExceptFunctionThrowsQuery extends NoexceptFunctionShouldNotPropagateToTheCallerSharedQuery { + NoExceptFunctionThrowsQuery() { this = Exceptions1Package::noExceptFunctionThrowsQuery() } } - -from - NoExceptThrowingFunction f, ExceptionFlowNode exceptionSource, ExceptionFlowNode functionNode, - ExceptionType exceptionType -where - not isExcluded(f, Exceptions1Package::noExceptFunctionThrowsQuery()) and - f.hasExceptionFlow(exceptionSource, functionNode, exceptionType) -select f, exceptionSource, functionNode, - "Function " + f.getName() + " is declared noexcept(true) but can throw exceptions of type " + - exceptionType.getExceptionName() + "." diff --git a/cpp/autosar/src/rules/A18-1-2/VectorboolSpecializationUsed.ql b/cpp/autosar/src/rules/A18-1-2/VectorboolSpecializationUsed.ql index 2d94fde98c..5bbe181927 100644 --- a/cpp/autosar/src/rules/A18-1-2/VectorboolSpecializationUsed.ql +++ b/cpp/autosar/src/rules/A18-1-2/VectorboolSpecializationUsed.ql @@ -17,23 +17,10 @@ import cpp import codingstandards.cpp.autosar -import codingstandards.cpp.StdNamespace +import codingstandards.cpp.rules.vectorshouldnotbespecializedwithbool.VectorShouldNotBeSpecializedWithBool -predicate isVectorBool(ClassTemplateInstantiation c) { - c.getNamespace() instanceof StdNS and - c.getTemplateArgument(0) instanceof BoolType and - c.getSimpleName() = "vector" +class VectorboolSpecializationUsedQuery extends VectorShouldNotBeSpecializedWithBoolSharedQuery { + VectorboolSpecializationUsedQuery() { + this = BannedTypesPackage::vectorboolSpecializationUsedQuery() + } } - -predicate isUsingVectorBool(ClassTemplateInstantiation c) { - isVectorBool(c) or - isUsingVectorBool(c.getTemplateArgument(_)) -} - -from Variable v, ClassTemplateInstantiation c -where - v.getUnderlyingType() = c and - not v.isFromTemplateInstantiation(_) and - isUsingVectorBool(c) and - not isExcluded(v, BannedTypesPackage::vectorboolSpecializationUsedQuery()) -select v, "Use of std::vector specialization." diff --git a/cpp/autosar/src/rules/A18-5-4/GlobalSizedOperatorDeleteNotDefined.ql b/cpp/autosar/src/rules/A18-5-4/GlobalSizedOperatorDeleteNotDefined.ql index 7819cfad4d..274b18301c 100644 --- a/cpp/autosar/src/rules/A18-5-4/GlobalSizedOperatorDeleteNotDefined.ql +++ b/cpp/autosar/src/rules/A18-5-4/GlobalSizedOperatorDeleteNotDefined.ql @@ -15,14 +15,11 @@ import cpp import codingstandards.cpp.autosar -import OperatorDelete +import codingstandards.cpp.rules.globalsizedoperatordeletenotdefined.GlobalSizedOperatorDeleteNotDefined -from OperatorDelete unsized_delete -where - not isExcluded(unsized_delete, DeclarationsPackage::globalSizedOperatorDeleteNotDefinedQuery()) and - not unsized_delete.isSizeDelete() and - not exists(OperatorDelete od | unsized_delete.isNoThrowDelete() = od.isNoThrowDelete() | - od.isSizeDelete() - ) -select unsized_delete, - "Unsized function '" + unsized_delete.getName() + "' defined globally without sized version." +class GlobalSizedOperatorDeleteNotDefinedQuery extends GlobalSizedOperatorDeleteNotDefinedSharedQuery +{ + GlobalSizedOperatorDeleteNotDefinedQuery() { + this = DeclarationsPackage::globalSizedOperatorDeleteNotDefinedQuery() + } +} diff --git a/cpp/autosar/src/rules/A18-5-4/GlobalUnsizedOperatorDeleteNotDefined.ql b/cpp/autosar/src/rules/A18-5-4/GlobalUnsizedOperatorDeleteNotDefined.ql index 2c96660704..2bd0ada800 100644 --- a/cpp/autosar/src/rules/A18-5-4/GlobalUnsizedOperatorDeleteNotDefined.ql +++ b/cpp/autosar/src/rules/A18-5-4/GlobalUnsizedOperatorDeleteNotDefined.ql @@ -15,14 +15,11 @@ import cpp import codingstandards.cpp.autosar -import OperatorDelete +import codingstandards.cpp.rules.globalunsizedoperatordeletenotdefined.GlobalUnsizedOperatorDeleteNotDefined -from OperatorDelete sized_delete -where - not isExcluded(sized_delete, DeclarationsPackage::globalUnsizedOperatorDeleteNotDefinedQuery()) and - sized_delete.isSizeDelete() and - not exists(OperatorDelete od | sized_delete.isNoThrowDelete() = od.isNoThrowDelete() | - not od.isSizeDelete() - ) -select sized_delete, - "Sized function '" + sized_delete.getName() + "' defined globally without unsized version." +class GlobalUnsizedOperatorDeleteNotDefinedQuery extends GlobalUnsizedOperatorDeleteNotDefinedSharedQuery +{ + GlobalUnsizedOperatorDeleteNotDefinedQuery() { + this = DeclarationsPackage::globalUnsizedOperatorDeleteNotDefinedQuery() + } +} diff --git a/cpp/autosar/src/rules/A18-9-2/ForwardingValuesToOtherFunctions.ql b/cpp/autosar/src/rules/A18-9-2/ForwardingValuesToOtherFunctions.ql index b0dd714209..72de362ebc 100644 --- a/cpp/autosar/src/rules/A18-9-2/ForwardingValuesToOtherFunctions.ql +++ b/cpp/autosar/src/rules/A18-9-2/ForwardingValuesToOtherFunctions.ql @@ -14,20 +14,12 @@ */ import cpp -import codingstandards.cpp.standardlibrary.Utility import codingstandards.cpp.autosar +import codingstandards.cpp.rules.forwardingreferencesandforwardnotusedtogether.ForwardingReferencesAndForwardNotUsedTogether -from FunctionCall c, Parameter a, string message -where - not isExcluded(c, MoveForwardPackage::forwardingValuesToOtherFunctionsQuery()) and - a.getAnAccess() = c.getAnArgument() and - ( - c instanceof StdMoveCall and - a instanceof ForwardParameter and - message = "Function `std::forward` should be used for forwarding the forward reference $@." - or - c instanceof StdForwardCall and - a instanceof ConsumeParameter and - message = "Function `std::move` should be used for forwarding rvalue reference $@." - ) -select c, message, a, a.getName() +class ForwardingValuesToOtherFunctionsQuery extends ForwardingReferencesAndForwardNotUsedTogetherSharedQuery +{ + ForwardingValuesToOtherFunctionsQuery() { + this = MoveForwardPackage::forwardingValuesToOtherFunctionsQuery() + } +} diff --git a/cpp/autosar/src/rules/A2-13-1/EscapeSequenceOutsideISO.ql b/cpp/autosar/src/rules/A2-13-1/EscapeSequenceOutsideISO.ql index d8382f51c8..0f1d9a3271 100644 --- a/cpp/autosar/src/rules/A2-13-1/EscapeSequenceOutsideISO.ql +++ b/cpp/autosar/src/rules/A2-13-1/EscapeSequenceOutsideISO.ql @@ -16,11 +16,8 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.backslashcharactermisuse.BackslashCharacterMisuse -from StringLiteral l, string es -where - not isExcluded(l, LiteralsPackage::escapeSequenceOutsideISOQuery()) and - es = l.getANonStandardEscapeSequence(_, _) and - // Exclude universal-character-names, which begin with \u or \U - not es.toLowerCase().matches("\\u") -select l, "This literal contains the non-standard escape sequence " + es + "." +class EscapeSequenceOutsideISOQuery extends BackslashCharacterMisuseSharedQuery { + EscapeSequenceOutsideISOQuery() { this = LiteralsPackage::escapeSequenceOutsideISOQuery() } +} diff --git a/cpp/autosar/src/rules/A2-7-1/SingleLineCommentEndsWithSlash.ql b/cpp/autosar/src/rules/A2-7-1/SingleLineCommentEndsWithSlash.ql index adbb1dccea..cd7d7c42cd 100644 --- a/cpp/autosar/src/rules/A2-7-1/SingleLineCommentEndsWithSlash.ql +++ b/cpp/autosar/src/rules/A2-7-1/SingleLineCommentEndsWithSlash.ql @@ -17,9 +17,10 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.linesplicingusedincomments.LineSplicingUsedInComments -from CppStyleComment c -where - not isExcluded(c, CommentsPackage::singleLineCommentEndsWithSlashQuery()) and - exists(c.getContents().regexpFind("\\\n", _, _)) -select c, "C++ comment includes \\ as the last character of a line" +class SingleLineCommentEndsWithSlashQuery extends LineSplicingUsedInCommentsSharedQuery { + SingleLineCommentEndsWithSlashQuery() { + this = CommentsPackage::singleLineCommentEndsWithSlashQuery() + } +} diff --git a/cpp/autosar/src/rules/A4-10-1/NullPointerConstantNotNullptr.ql b/cpp/autosar/src/rules/A4-10-1/NullPointerConstantNotNullptr.ql index e77c8265d5..ce3c6f8461 100644 --- a/cpp/autosar/src/rules/A4-10-1/NullPointerConstantNotNullptr.ql +++ b/cpp/autosar/src/rules/A4-10-1/NullPointerConstantNotNullptr.ql @@ -16,17 +16,11 @@ import cpp import codingstandards.cpp.autosar -import semmle.code.cpp.commons.NULL +import codingstandards.cpp.rules.nullptrnottheonlyformofthenullpointerconstant.NullptrNotTheOnlyFormOfTheNullPointerConstant -from Literal l -where - not isExcluded(l, LiteralsPackage::nullPointerConstantNotNullptrQuery()) and - // Not the type of the nullptr literal - not l.getType() instanceof NullPointerType and - // Converted to a pointer type - l.getConversion().getType().getUnspecifiedType() instanceof PointerType and - // Value of zero - l.getValue() = "0" and - // Not the StringLiteral "0" - not l instanceof StringLiteral -select l, l.getValueText() + " is used as the null-pointer-constant but is not nullptr." +class NullPointerConstantNotNullptrQuery extends NullptrNotTheOnlyFormOfTheNullPointerConstantSharedQuery +{ + NullPointerConstantNotNullptrQuery() { + this = LiteralsPackage::nullPointerConstantNotNullptrQuery() + } +} diff --git a/cpp/autosar/src/rules/A5-10-1/PointerToMemberVirtualFunctionWithNullPointerConstant.ql b/cpp/autosar/src/rules/A5-10-1/PointerToMemberVirtualFunctionWithNullPointerConstant.ql index 2289dc4e79..825347754d 100644 --- a/cpp/autosar/src/rules/A5-10-1/PointerToMemberVirtualFunctionWithNullPointerConstant.ql +++ b/cpp/autosar/src/rules/A5-10-1/PointerToMemberVirtualFunctionWithNullPointerConstant.ql @@ -16,19 +16,11 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.potentiallyvirtualpointeronlycomparestonullptr.PotentiallyVirtualPointerOnlyComparesToNullptr -from - EqualityOperation equalityComparison, MemberFunction virtualFunction, - FunctionAccess accessOperand, Expr otherOperand -where - not isExcluded(equalityComparison, - PointersPackage::pointerToMemberVirtualFunctionWithNullPointerConstantQuery()) and - virtualFunction.isVirtual() and - equalityComparison.getAnOperand() = accessOperand and - accessOperand.getTarget() = virtualFunction and - otherOperand = equalityComparison.getAnOperand() and - not otherOperand = accessOperand and - not otherOperand.getType() instanceof NullPointerType -select equalityComparison, - "A pointer to member virtual function $@ is tested for equality with non-null-pointer-constant $@. ", - virtualFunction, virtualFunction.getName(), otherOperand, otherOperand.toString() +class PointerToMemberVirtualFunctionWithNullPointerConstantQuery extends PotentiallyVirtualPointerOnlyComparesToNullptrSharedQuery +{ + PointerToMemberVirtualFunctionWithNullPointerConstantQuery() { + this = PointersPackage::pointerToMemberVirtualFunctionWithNullPointerConstantQuery() + } +} diff --git a/cpp/autosar/src/rules/A5-2-4/ReinterpretCastUsed.ql b/cpp/autosar/src/rules/A5-2-4/ReinterpretCastUsed.ql index 92cf12d8a0..bf5805698d 100644 --- a/cpp/autosar/src/rules/A5-2-4/ReinterpretCastUsed.ql +++ b/cpp/autosar/src/rules/A5-2-4/ReinterpretCastUsed.ql @@ -16,7 +16,8 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.reinterpretcastused.ReinterpretCastUsed -from ReinterpretCast rc -where not isExcluded(rc, BannedSyntaxPackage::reinterpretCastUsedQuery()) -select rc, "Use of reinterpret_cast." +class ReinterpretCastUsedQuery extends ReinterpretCastUsedSharedQuery { + ReinterpretCastUsedQuery() { this = BannedSyntaxPackage::reinterpretCastUsedQuery() } +} diff --git a/cpp/autosar/src/rules/A6-6-1/GotoStatementUsed.ql b/cpp/autosar/src/rules/A6-6-1/GotoStatementUsed.ql index 5e1c10e4c7..03b891e6db 100644 --- a/cpp/autosar/src/rules/A6-6-1/GotoStatementUsed.ql +++ b/cpp/autosar/src/rules/A6-6-1/GotoStatementUsed.ql @@ -16,9 +16,8 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.gotostatementshouldnotbeused.GotoStatementShouldNotBeUsed -from Stmt s -where - not isExcluded(s, BannedSyntaxPackage::gotoStatementUsedQuery()) and - (s instanceof GotoStmt or s instanceof ComputedGotoStmt) -select s, "Use of goto." +class GotoStatementUsedQuery extends GotoStatementShouldNotBeUsedSharedQuery { + GotoStatementUsedQuery() { this = BannedSyntaxPackage::gotoStatementUsedQuery() } +} diff --git a/cpp/autosar/src/rules/A7-2-2/EnumerationUnderlyingBaseTypeNotExplicitlyDefined.ql b/cpp/autosar/src/rules/A7-2-2/EnumerationUnderlyingBaseTypeNotExplicitlyDefined.ql index cf5273f45d..42924945cd 100644 --- a/cpp/autosar/src/rules/A7-2-2/EnumerationUnderlyingBaseTypeNotExplicitlyDefined.ql +++ b/cpp/autosar/src/rules/A7-2-2/EnumerationUnderlyingBaseTypeNotExplicitlyDefined.ql @@ -17,9 +17,11 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.enumerationnotdefinedwithanexplicitunderlyingtype.EnumerationNotDefinedWithAnExplicitUnderlyingType -from Enum e -where - not isExcluded(e, DeclarationsPackage::enumerationUnderlyingBaseTypeNotExplicitlyDefinedQuery()) and - not e.hasExplicitUnderlyingType() -select e, "Base type of enumeration is not explicitly specified." +class EnumerationUnderlyingBaseTypeNotExplicitlyDefinedQuery extends EnumerationNotDefinedWithAnExplicitUnderlyingTypeSharedQuery +{ + EnumerationUnderlyingBaseTypeNotExplicitlyDefinedQuery() { + this = DeclarationsPackage::enumerationUnderlyingBaseTypeNotExplicitlyDefinedQuery() + } +} diff --git a/cpp/autosar/src/rules/A7-3-1/DefinitionNotConsideredForUnqualifiedLookup.ql b/cpp/autosar/src/rules/A7-3-1/DefinitionNotConsideredForUnqualifiedLookup.ql index ac6e1b6ff9..75cb2016b5 100644 --- a/cpp/autosar/src/rules/A7-3-1/DefinitionNotConsideredForUnqualifiedLookup.ql +++ b/cpp/autosar/src/rules/A7-3-1/DefinitionNotConsideredForUnqualifiedLookup.ql @@ -16,56 +16,11 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.definitionnotconsideredforunqualifiedlookup.DefinitionNotConsideredForUnqualifiedLookup -/** - * Holds if `functionDecl` is a possible intended target of the `usingDecl`. - */ -pragma[noinline] -predicate isPossibleIntendedTarget( - FunctionDeclarationEntry functionDecl, UsingDeclarationEntry usingDecl -) { - // Extracted to improve the join order. With this approach, we first compute a set of using - // declarations and a set of possible intended targets - functionDecl.getDeclaration().isTopLevel() and - functionDecl.getDeclaration().getQualifiedName() = usingDecl.getDeclaration().getQualifiedName() and - functionDecl.getDeclaration().getNamespace().getParentNamespace*() = usingDecl.getParentScope() +class DefinitionNotConsideredForUnqualifiedLookupQuery extends DefinitionNotConsideredForUnqualifiedLookupSharedQuery +{ + DefinitionNotConsideredForUnqualifiedLookupQuery() { + this = ScopePackage::definitionNotConsideredForUnqualifiedLookupQuery() + } } - -/** - * Holds if `functionDecl` is a possible intended target of the `usingDecl`, and they exist at the - * given locations. - */ -pragma[noinline] -predicate isPossibleIntendedTargetLocation( - FunctionDeclarationEntry functionDecl, UsingDeclarationEntry usingDecl, File usingsFile, - File unavailableFile, int usingsStartLine, int unavailableStartLine -) { - // Extracted to improve the join order. With this approach, we take the set of possible intended - // targets computed in isPossibleIntendedTargets, and compute the files and start lines. - // This helps avoid the join order preferred by the optimiser if this is all written directly in - // the from-where-select, where it will eagerly join: - // - // usingDeclarationEntries -> enclosing files -> all other elements in those files - // - // which is expensive when there are a lot of files with using declarations - isPossibleIntendedTarget(functionDecl, usingDecl) and - usingsFile = usingDecl.getFile() and - unavailableFile = functionDecl.getFile() and - usingsStartLine = usingDecl.getLocation().getStartLine() and - unavailableStartLine = functionDecl.getLocation().getStartLine() -} - -from FunctionDeclarationEntry unavailableDecl, UsingDeclarationEntry usingDecl -where - not isExcluded(unavailableDecl, ScopePackage::definitionNotConsideredForUnqualifiedLookupQuery()) and - exists(File usingsFile, File unavailableFile, int usingsStartLine, int unavailableStartLine | - isPossibleIntendedTargetLocation(unavailableDecl, usingDecl, usingsFile, unavailableFile, - usingsStartLine, unavailableStartLine) and - // An approximation of order where we want the using to preceed the new declaration. - usingsFile = unavailableFile and - usingsStartLine < unavailableStartLine - ) -select unavailableDecl, - "Definition for '" + unavailableDecl.getName() + - "' is not available for unqualified lookup because it is declared after $@", usingDecl, - "using-declaration" diff --git a/cpp/autosar/src/rules/A7-3-1/HiddenInheritedNonOverridableMemberFunction.ql b/cpp/autosar/src/rules/A7-3-1/HiddenInheritedNonOverridableMemberFunction.ql index fa1859c229..fd9602f218 100644 --- a/cpp/autosar/src/rules/A7-3-1/HiddenInheritedNonOverridableMemberFunction.ql +++ b/cpp/autosar/src/rules/A7-3-1/HiddenInheritedNonOverridableMemberFunction.ql @@ -15,45 +15,11 @@ import cpp import codingstandards.cpp.autosar -import codingstandards.cpp.Class +import codingstandards.cpp.rules.hiddeninheritednonoverridablememberfunction.HiddenInheritedNonOverridableMemberFunction -/** - * Holds if the class has a non-virtual member function with the given name. - */ -pragma[noinline, nomagic] -predicate hasNonVirtualMemberFunction(Class clazz, MemberFunction mf, string name) { - mf.getDeclaringType() = clazz and - mf.getName() = name and - not mf.isVirtual() and - // Exclude private member functions, which cannot be inherited. - not mf.isPrivate() +class HiddenInheritedNonOverridableMemberFunctionQuery extends HiddenInheritedNonOverridableMemberFunctionSharedQuery +{ + HiddenInheritedNonOverridableMemberFunctionQuery() { + this = ScopePackage::hiddenInheritedNonOverridableMemberFunctionQuery() + } } - -/** - * Holds if the member function is in a class with the given base class, and has the given name. - */ -pragma[noinline, nomagic] -predicate hasDeclarationBaseClass(MemberFunction mf, Class baseClass, string functionName) { - baseClass = mf.getDeclaringType().getABaseClass() and - functionName = mf.getName() -} - -from MemberFunction overridingDecl, MemberFunction hiddenDecl, Class baseClass, string name -where - not isExcluded(overridingDecl, ScopePackage::hiddenInheritedNonOverridableMemberFunctionQuery()) and - // Check if we are overriding a non-virtual inherited member function - hasNonVirtualMemberFunction(baseClass, hiddenDecl, name) and - hasDeclarationBaseClass(overridingDecl, baseClass, name) and - // Where the hidden member function isn't explicitly brought in scope through a using declaration. - not exists(UsingDeclarationEntry ude | - ude.getDeclaration() = hiddenDecl and - ude.getEnclosingElement() = overridingDecl.getDeclaringType() - ) and - // Exclude compiler generated member functions which include things like copy constructor that hide base class - // copy constructors. - not overridingDecl.isCompilerGenerated() and - // Exclude special member functions, which cannot be inherited. - not overridingDecl instanceof SpecialMemberFunction -select overridingDecl, - "Declaration for member '" + name + "' hides non-overridable inherited member function $@", - hiddenDecl, hiddenDecl.getName() diff --git a/cpp/autosar/src/rules/A7-3-1/HiddenInheritedOverridableMemberFunction.ql b/cpp/autosar/src/rules/A7-3-1/HiddenInheritedOverridableMemberFunction.ql index 437c8798f9..aa9105f9de 100644 --- a/cpp/autosar/src/rules/A7-3-1/HiddenInheritedOverridableMemberFunction.ql +++ b/cpp/autosar/src/rules/A7-3-1/HiddenInheritedOverridableMemberFunction.ql @@ -15,42 +15,11 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.hiddeninheritedoverridablememberfunction.HiddenInheritedOverridableMemberFunction -from FunctionDeclarationEntry overridingDecl, FunctionDeclarationEntry hiddenDecl -where - not isExcluded(overridingDecl, ScopePackage::hiddenInheritedOverridableMemberFunctionQuery()) and - // Check if we are overriding a virtual inherited member function - hiddenDecl.getDeclaration().isVirtual() and - // Exclude private member functions, which cannot be inherited. - not hiddenDecl.getDeclaration().(MemberFunction).isPrivate() and - // The overriding declaration hides the hidden declaration if: - ( - // 1. the overriding declaration overrides a function in a base class that is an overload of the hidden declaration - // and the hidden declaration isn't overriden in the same class. - exists(FunctionDeclarationEntry overridenDecl | - overridingDecl.getDeclaration().(MemberFunction).overrides(overridenDecl.getDeclaration()) and - overridenDecl.getDeclaration().getAnOverload() = hiddenDecl.getDeclaration() and - not exists(MemberFunction overridingFunc | - hiddenDecl.getDeclaration().(MemberFunction).getAnOverridingFunction() = overridingFunc and - overridingFunc.getDeclaringType() = overridingDecl.getDeclaration().getDeclaringType() - ) - ) and - // and the hidden declaration isn't explicitly brought in scope through a using declaration. - not exists(UsingDeclarationEntry ude | - ude.getDeclaration() = hiddenDecl.getDeclaration() and - ude.getEnclosingElement() = overridingDecl.getDeclaration().getDeclaringType() - ) - or - // 2. if the overriding declaration doesn't override a base member function but has the same name - // as the hidden declaration - not overridingDecl.getDeclaration().(MemberFunction).overrides(_) and - overridingDecl.getName() = hiddenDecl.getName() and - overridingDecl.getDeclaration().getDeclaringType().getABaseClass() = - hiddenDecl.getDeclaration().getDeclaringType() - ) and - // Limit the results to the declarations and not the definitions, if any. - (overridingDecl.getDeclaration().hasDefinition() implies not overridingDecl.isDefinition()) and - (hiddenDecl.getDeclaration().hasDefinition() implies not hiddenDecl.isDefinition()) -select overridingDecl, - "Declaration for member '" + overridingDecl.getName() + - "' hides overridable inherited member function $@", hiddenDecl, hiddenDecl.getName() +class HiddenInheritedOverridableMemberFunctionQuery extends HiddenInheritedOverridableMemberFunctionSharedQuery +{ + HiddenInheritedOverridableMemberFunctionQuery() { + this = ScopePackage::hiddenInheritedOverridableMemberFunctionQuery() + } +} diff --git a/cpp/autosar/src/rules/A7-4-1/AsmDeclarationUsed.ql b/cpp/autosar/src/rules/A7-4-1/AsmDeclarationUsed.ql index d94811ff18..44489151da 100644 --- a/cpp/autosar/src/rules/A7-4-1/AsmDeclarationUsed.ql +++ b/cpp/autosar/src/rules/A7-4-1/AsmDeclarationUsed.ql @@ -15,7 +15,8 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.asmdeclarationused.AsmDeclarationUsed -from AsmStmt a -where not isExcluded(a, BannedSyntaxPackage::asmDeclarationUsedQuery()) -select a, "Use of asm declaration" +class AsmDeclarationUsedQuery extends AsmDeclarationUsedSharedQuery { + AsmDeclarationUsedQuery() { this = BannedSyntaxPackage::asmDeclarationUsedQuery() } +} diff --git a/cpp/autosar/src/rules/A7-5-2/RecursiveFunctions.ql b/cpp/autosar/src/rules/A7-5-2/RecursiveFunctions.ql index 13883624b3..6b305d9ca9 100644 --- a/cpp/autosar/src/rules/A7-5-2/RecursiveFunctions.ql +++ b/cpp/autosar/src/rules/A7-5-2/RecursiveFunctions.ql @@ -16,21 +16,8 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.functionscallthemselveseitherdirectlyorindirectly.FunctionsCallThemselvesEitherDirectlyOrIndirectly -class RecursiveCall extends FunctionCall { - RecursiveCall() { - this.getTarget().calls*(this.getEnclosingFunction()) and - not this.getTarget().hasSpecifier("is_constexpr") - } +class RecursiveFunctionsQuery extends FunctionsCallThemselvesEitherDirectlyOrIndirectlySharedQuery { + RecursiveFunctionsQuery() { this = FunctionsPackage::recursiveFunctionsQuery() } } - -from RecursiveCall call, string msg, FunctionCall fc -where - not isExcluded(fc, FunctionsPackage::recursiveFunctionsQuery()) and - fc.getTarget() = call.getTarget() and - if fc.getTarget() = fc.getEnclosingFunction() - then msg = "This call directly invokes its containing function $@." - else - msg = - "The function " + fc.getEnclosingFunction() + " is indirectly recursive via this call to $@." -select fc, msg, fc.getTarget(), fc.getTarget().getName() diff --git a/cpp/autosar/src/rules/A8-5-4/ConfusingUseOfInitializerListConstructors.ql b/cpp/autosar/src/rules/A8-5-4/ConfusingUseOfInitializerListConstructors.ql index 2a44ca650e..180cbf7224 100644 --- a/cpp/autosar/src/rules/A8-5-4/ConfusingUseOfInitializerListConstructors.ql +++ b/cpp/autosar/src/rules/A8-5-4/ConfusingUseOfInitializerListConstructors.ql @@ -17,50 +17,11 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.initializerlistconstructoristheonlyconstructor.InitializerListConstructorIsTheOnlyConstructor -class StdInitializerList extends Class { - StdInitializerList() { hasQualifiedName("std", "initializer_list") } -} - -/** - * An _initializer-list constructor_ according to `[dcl.init.list]`. - * - * A `Constructor` where the first parameter refers to `std::initializer_list`, and any remaining - * parameters have default arguments. - */ -class InitializerListConstructor extends Constructor { - InitializerListConstructor() { - // The first parameter is a `std::intializer_list` parameter - exists(Type firstParamType | firstParamType = getParameter(0).getType() | - // Either directly `std::initializer_list` - firstParamType instanceof StdInitializerList - or - //A reference to `std::initializer_list` - firstParamType.(ReferenceType).getBaseType().getUnspecifiedType() instanceof - StdInitializerList - ) and - // All parameters other than the fi - forall(Parameter other | other = getParameter([1 .. (getNumberOfParameters() - 1)]) | - exists(other.getInitializer()) - ) +class ConfusingUseOfInitializerListConstructorsQuery extends InitializerListConstructorIsTheOnlyConstructorSharedQuery +{ + ConfusingUseOfInitializerListConstructorsQuery() { + this = InitializationPackage::confusingUseOfInitializerListConstructorsQuery() } } - -from Constructor c, InitializerListConstructor stdInitializerConstructor, string paramList -where - not isExcluded(c, InitializationPackage::confusingUseOfInitializerListConstructorsQuery()) and - // Not an initializer-list constructor - not c instanceof InitializerListConstructor and - // Constructor is not a special member function constructor - not c instanceof CopyConstructor and - not c instanceof MoveConstructor and - not c.getNumberOfParameters() = 0 and // default constructor - // And there is an initalizer-list constructor - stdInitializerConstructor = c.getDeclaringType().getAConstructor() and - // Determine the parameter type list of the constructor - paramList = - concat(string parameter | parameter = c.getAParameter().getType().getName() | parameter, ",") -select c, - "The constructor " + c.getQualifiedName() + "(" + paramList + - ") may be ignored in favour of $@ when using braced initialization.", stdInitializerConstructor, - "the constructor accepting std::initializer_list" diff --git a/cpp/autosar/src/rules/M10-1-3/AccessibleBaseClassBothVirtualAndNonVirtualInHierarchy.ql b/cpp/autosar/src/rules/M10-1-3/AccessibleBaseClassBothVirtualAndNonVirtualInHierarchy.ql index 6b6cead0ea..c16e5461f0 100644 --- a/cpp/autosar/src/rules/M10-1-3/AccessibleBaseClassBothVirtualAndNonVirtualInHierarchy.ql +++ b/cpp/autosar/src/rules/M10-1-3/AccessibleBaseClassBothVirtualAndNonVirtualInHierarchy.ql @@ -14,24 +14,11 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.virtualandnonvirtualclassinthehierarchy.VirtualAndNonVirtualClassInTheHierarchy -from Class c1, Class c2, Class c3, Class base, ClassDerivation cd1, ClassDerivation cd2 -where - not isExcluded(c3, - InheritancePackage::accessibleBaseClassBothVirtualAndNonVirtualInHierarchyQuery()) and - // for each pair of classes, get all of their derivations - cd1 = c1.getADerivation() and - cd2 = c2.getADerivation() and - // where they share the same base class - base = cd1.getBaseClass() and - base = cd2.getBaseClass() and - // but one is virtual, and one is not, and the derivations are in different classes - cd1.isVirtual() and - not cd2.isVirtual() and - // and there is some 'other class' that derives from both of these classes - c3.derivesFrom*(c1) and - c3.derivesFrom*(c2) and - // and the base class is accessible from the 'other class' - c3.getAMemberFunction().getEnclosingAccessHolder().canAccessClass(base, c3) -select c3, "Class inherits base class $@, which is derived virtual by $@ and non-virtual by $@.", - base, base.getName(), cd1, cd1.getDerivedClass().toString(), c2, cd2.getDerivedClass().toString() +class AccessibleBaseClassBothVirtualAndNonVirtualInHierarchyQuery extends VirtualAndNonVirtualClassInTheHierarchySharedQuery +{ + AccessibleBaseClassBothVirtualAndNonVirtualInHierarchyQuery() { + this = InheritancePackage::accessibleBaseClassBothVirtualAndNonVirtualInHierarchyQuery() + } +} diff --git a/cpp/autosar/src/rules/M12-1-1/DynamicTypeOfThisUsedFromConstructorOrDestructor.ql b/cpp/autosar/src/rules/M12-1-1/DynamicTypeOfThisUsedFromConstructorOrDestructor.ql index 35f41c179a..4b6c037aba 100644 --- a/cpp/autosar/src/rules/M12-1-1/DynamicTypeOfThisUsedFromConstructorOrDestructor.ql +++ b/cpp/autosar/src/rules/M12-1-1/DynamicTypeOfThisUsedFromConstructorOrDestructor.ql @@ -14,79 +14,11 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.objectsdynamictypeusedfromconstructorordestructor.ObjectsDynamicTypeUsedFromConstructorOrDestructor -predicate thisCall(FunctionCall c) { - c.getQualifier() instanceof ThisExpr or - c.getQualifier().(PointerDereferenceExpr).getChild(0) instanceof ThisExpr -} - -predicate virtualThisCall(FunctionCall c, Function overridingFunction) { - c.isVirtual() and - thisCall(c) and - overridingFunction = c.getTarget().(VirtualFunction).getAnOverridingFunction() -} - -class DynamicTypeExpr extends Expr { - DynamicTypeExpr() { - this instanceof TypeidOperator and - this.getEnclosingFunction().getDeclaringType().isPolymorphic() - or - this instanceof DynamicCast - or - virtualThisCall(this.(FunctionCall), _) +class DynamicTypeOfThisUsedFromConstructorOrDestructorQuery extends ObjectsDynamicTypeUsedFromConstructorOrDestructorSharedQuery +{ + DynamicTypeOfThisUsedFromConstructorOrDestructorQuery() { + this = InheritancePackage::dynamicTypeOfThisUsedFromConstructorOrDestructorQuery() } } - -/* - * Catch most cases: go into functions in the same class, but only catch direct - * references to "this". - */ - -predicate nonVirtualMemberFunction(MemberFunction mf, Class c) { - mf = c.getAMemberFunction() and - not mf instanceof Constructor and - not mf instanceof Destructor and - not mf.isVirtual() -} - -predicate callFromNonVirtual(MemberFunction source, Class c, MemberFunction targ) { - exists(FunctionCall fc | - fc.getEnclosingFunction() = source and fc.getTarget() = targ and thisCall(fc) - ) and - targ = c.getAMemberFunction() and - nonVirtualMemberFunction(source, c) -} - -predicate indirectlyInvokesDynamicTypeExpr(MemberFunction caller, DynamicTypeExpr target) { - target = - any(DynamicTypeExpr expr | - expr.getEnclosingFunction() = caller and - nonVirtualMemberFunction(caller, caller.getDeclaringType()) - ) - or - exists(MemberFunction mid | - indirectlyInvokesDynamicTypeExpr(mid, target) and - callFromNonVirtual(caller, caller.getDeclaringType(), mid) - ) -} - -from DynamicTypeExpr expr, FunctionCall call, MemberFunction mf, string explanation -where - not isExcluded(expr, InheritancePackage::dynamicTypeOfThisUsedFromConstructorOrDestructorQuery()) and - ( - mf instanceof Constructor or - mf instanceof Destructor - ) and - ( - mf = expr.getEnclosingFunction() and - explanation = "$@ uses the dynamic type of its own object." - or - mf != expr.getEnclosingFunction() and - mf = call.getEnclosingFunction() and - thisCall(call) and - indirectlyInvokesDynamicTypeExpr(call.getTarget(), expr) and - explanation = - "$@ calls " + call.getTarget().getQualifiedName() + - ", which uses the dynamic type of its own object." - ) -select expr, explanation, mf, mf.getQualifiedName() diff --git a/cpp/autosar/src/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThis.ql b/cpp/autosar/src/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThis.ql index 2736d39290..486a428474 100644 --- a/cpp/autosar/src/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThis.ql +++ b/cpp/autosar/src/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThis.ql @@ -16,27 +16,11 @@ import cpp import codingstandards.cpp.autosar -import NameInDependentBase +import codingstandards.cpp.rules.namenotreferredusingaqualifiedidorthis.NameNotReferredUsingAQualifiedIdOrThis -from - TemplateClass c, NameQualifiableElement fn, string targetName, Element actualTarget, - Element dependentTypeMemberWithSameName -where - not isExcluded(fn, TemplatesPackage::nameNotReferredUsingAQualifiedIdOrThisQuery()) and - not isCustomExcluded(fn) and - missingNameQualifier(fn) and - ( - fn = getConfusingFunctionAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName) - or - fn = getConfusingFunctionCall(c, targetName, actualTarget, dependentTypeMemberWithSameName) and - not exists(Expr e | e = fn.(FunctionCall).getQualifier()) - or - fn = - getConfusingMemberVariableAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName) and - not exists(Expr e | e = fn.(VariableAccess).getQualifier()) - ) and - not fn.isAffectedByMacro() -select fn, - "Use of unqualified identifier " + targetName + - " targets $@ but a member with the name also exists $@.", actualTarget, targetName, - dependentTypeMemberWithSameName, "in the dependent base class" +class NameNotReferredUsingAQualifiedIdOrThisQuery extends NameNotReferredUsingAQualifiedIdOrThisSharedQuery +{ + NameNotReferredUsingAQualifiedIdOrThisQuery() { + this = TemplatesPackage::nameNotReferredUsingAQualifiedIdOrThisQuery() + } +} diff --git a/cpp/autosar/src/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThisAudit.ql b/cpp/autosar/src/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThisAudit.ql index 401edf3b61..ea56b841ed 100644 --- a/cpp/autosar/src/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThisAudit.ql +++ b/cpp/autosar/src/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThisAudit.ql @@ -16,27 +16,11 @@ import cpp import codingstandards.cpp.autosar -import NameInDependentBase +import codingstandards.cpp.rules.namenotreferredusingaqualifiedidorthisaudit.NameNotReferredUsingAQualifiedIdOrThisAudit -from - TemplateClass c, NameQualifiableElement fn, string targetName, Element actualTarget, - Element dependentTypeMemberWithSameName -where - not isExcluded(fn, TemplatesPackage::nameNotReferredUsingAQualifiedIdOrThisAuditQuery()) and - not isCustomExcluded(fn) and - missingNameQualifier(fn) and - ( - fn = getConfusingFunctionAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName) - or - fn = getConfusingFunctionCall(c, targetName, actualTarget, dependentTypeMemberWithSameName) and - not exists(Expr e | e = fn.(FunctionCall).getQualifier()) - or - not fn.(VariableAccess).getTarget() instanceof Parameter and - fn = - getConfusingMemberVariableAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName) and - not exists(Expr e | e = fn.(VariableAccess).getQualifier()) - ) -select fn, - "Use of unqualified identifier " + targetName + - " targets $@ but a member with the name also exists $@.", actualTarget, targetName, - dependentTypeMemberWithSameName, "in the dependent base class" +class NameNotReferredUsingAQualifiedIdOrThisAuditQuery extends NameNotReferredUsingAQualifiedIdOrThisAuditSharedQuery +{ + NameNotReferredUsingAQualifiedIdOrThisAuditQuery() { + this = TemplatesPackage::nameNotReferredUsingAQualifiedIdOrThisAuditQuery() + } +} diff --git a/cpp/autosar/src/rules/M15-1-3/EmptyThrowOutsideCatch.ql b/cpp/autosar/src/rules/M15-1-3/EmptyThrowOutsideCatch.ql index 7e263d66bb..9f99e7c356 100644 --- a/cpp/autosar/src/rules/M15-1-3/EmptyThrowOutsideCatch.ql +++ b/cpp/autosar/src/rules/M15-1-3/EmptyThrowOutsideCatch.ql @@ -15,9 +15,8 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.emptythrowonlywithinacatchhandler.EmptyThrowOnlyWithinACatchHandler -from ReThrowExpr re -where - not isExcluded(re, Exceptions1Package::emptyThrowOutsideCatchQuery()) and - not re.getEnclosingElement+() instanceof CatchBlock -select re, "Rethrow outside catch block" +class EmptyThrowOutsideCatchQuery extends EmptyThrowOnlyWithinACatchHandlerSharedQuery { + EmptyThrowOutsideCatchQuery() { this = Exceptions1Package::emptyThrowOutsideCatchQuery() } +} diff --git a/cpp/autosar/src/rules/M18-2-1/MacroOffsetofUsed.ql b/cpp/autosar/src/rules/M18-2-1/MacroOffsetofUsed.ql index a572497418..cd347be44d 100644 --- a/cpp/autosar/src/rules/M18-2-1/MacroOffsetofUsed.ql +++ b/cpp/autosar/src/rules/M18-2-1/MacroOffsetofUsed.ql @@ -15,9 +15,8 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.macrooffsetofused.MacroOffsetofUsed -from MacroInvocation mi -where - not isExcluded(mi, BannedFunctionsPackage::macroOffsetofUsedQuery()) and - mi.getMacroName() = "offsetof" -select mi, "Use of banned macro " + mi.getMacroName() + "." +class MacroOffsetofUsedQuery extends MacroOffsetofUsedSharedQuery { + MacroOffsetofUsedQuery() { this = BannedFunctionsPackage::macroOffsetofUsedQuery() } +} diff --git a/cpp/autosar/src/rules/M18-7-1/CsignalFunctionsUsed.ql b/cpp/autosar/src/rules/M18-7-1/CsignalFunctionsUsed.ql index ff264baffc..4df4715848 100644 --- a/cpp/autosar/src/rules/M18-7-1/CsignalFunctionsUsed.ql +++ b/cpp/autosar/src/rules/M18-7-1/CsignalFunctionsUsed.ql @@ -16,10 +16,8 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.csignalfunctionsused.CsignalFunctionsUsed -from FunctionCall fc, Function f -where - not isExcluded(fc, BannedLibrariesPackage::csignalFunctionsUsedQuery()) and - f = fc.getTarget() and - f.hasGlobalOrStdName(["signal", "raise"]) -select fc, "Use of function '" + f.getQualifiedName() + "'." +class CsignalFunctionsUsedQuery extends CsignalFunctionsUsedSharedQuery { + CsignalFunctionsUsedQuery() { this = BannedLibrariesPackage::csignalFunctionsUsedQuery() } +} diff --git a/cpp/autosar/src/rules/M18-7-1/CsignalTypesUsed.ql b/cpp/autosar/src/rules/M18-7-1/CsignalTypesUsed.ql index c91d56c572..89e9ca169a 100644 --- a/cpp/autosar/src/rules/M18-7-1/CsignalTypesUsed.ql +++ b/cpp/autosar/src/rules/M18-7-1/CsignalTypesUsed.ql @@ -16,10 +16,8 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.csignaltypesused.CsignalTypesUsed -from TypeMention tm, UserType ut -where - not isExcluded(tm, BannedLibrariesPackage::csignalTypesUsedQuery()) and - ut = tm.getMentionedType() and - ut.hasGlobalOrStdName("sig_atomic_t") -select tm, "Use of type '" + ut.getQualifiedName() + "'." +class CsignalTypesUsedQuery extends CsignalTypesUsedSharedQuery { + CsignalTypesUsedQuery() { this = BannedLibrariesPackage::csignalTypesUsedQuery() } +} diff --git a/cpp/autosar/src/rules/M2-13-2/UseOfNonZeroOctalLiteral.ql b/cpp/autosar/src/rules/M2-13-2/UseOfNonZeroOctalLiteral.ql index 2bd35e2484..b689edab6b 100644 --- a/cpp/autosar/src/rules/M2-13-2/UseOfNonZeroOctalLiteral.ql +++ b/cpp/autosar/src/rules/M2-13-2/UseOfNonZeroOctalLiteral.ql @@ -16,10 +16,8 @@ import cpp import codingstandards.cpp.autosar -import codingstandards.cpp.Cpp14Literal +import codingstandards.cpp.rules.useofnonzerooctalliteral.UseOfNonZeroOctalLiteral -from Cpp14Literal::OctalLiteral octalLiteral -where - not isExcluded(octalLiteral, LiteralsPackage::useOfNonZeroOctalLiteralQuery()) and - not octalLiteral.getValue() = "0" -select octalLiteral, "Non zero octal literal " + octalLiteral.getValueText() + "." +class UseOfNonZeroOctalLiteralQuery extends UseOfNonZeroOctalLiteralSharedQuery { + UseOfNonZeroOctalLiteralQuery() { this = LiteralsPackage::useOfNonZeroOctalLiteralQuery() } +} diff --git a/cpp/autosar/src/rules/M2-13-3/MissingUSuffix.ql b/cpp/autosar/src/rules/M2-13-3/MissingUSuffix.ql index 25cae1e03f..5bfa338864 100644 --- a/cpp/autosar/src/rules/M2-13-3/MissingUSuffix.ql +++ b/cpp/autosar/src/rules/M2-13-3/MissingUSuffix.ql @@ -18,18 +18,8 @@ import cpp import codingstandards.cpp.autosar -import codingstandards.cpp.Cpp14Literal +import codingstandards.cpp.rules.unsignedintegerliteralsnotappropriatelysuffixed.UnsignedIntegerLiteralsNotAppropriatelySuffixed -from Cpp14Literal::NumericLiteral nl, string literalKind -where - not isExcluded(nl, LiteralsPackage::missingUSuffixQuery()) and - ( - nl instanceof Cpp14Literal::OctalLiteral and literalKind = "Octal" - or - nl instanceof Cpp14Literal::HexLiteral and literalKind = "Hex" - ) and - // This either directly has an unsigned integer type, or it is converted to an unsigned integer type - nl.getType().getUnspecifiedType().(IntegralType).isUnsigned() and - // The literal already has a `u` or `U` suffix. - not nl.getValueText().regexpMatch(".*[lL]*[uU][lL]*") -select nl, literalKind + " literal is an unsigned integer but does not include a 'U' suffix." +class MissingUSuffixQuery extends UnsignedIntegerLiteralsNotAppropriatelySuffixedSharedQuery { + MissingUSuffixQuery() { this = LiteralsPackage::missingUSuffixQuery() } +} diff --git a/cpp/autosar/src/rules/M2-7-1/SlashStarUsedWithinACStyleComment.ql b/cpp/autosar/src/rules/M2-7-1/SlashStarUsedWithinACStyleComment.ql index 768acb0532..356a361cb1 100644 --- a/cpp/autosar/src/rules/M2-7-1/SlashStarUsedWithinACStyleComment.ql +++ b/cpp/autosar/src/rules/M2-7-1/SlashStarUsedWithinACStyleComment.ql @@ -16,9 +16,11 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.charactersequenceusedwithinacstylecomment.CharacterSequenceUsedWithinACStyleComment -from CStyleComment c -where - not isExcluded(c, CommentsPackage::slashStarUsedWithinACStyleCommentQuery()) and - exists(c.getContents().regexpFind("./\\*", _, _)) -select c, "C-style /* comment includes nested /*." +class SlashStarUsedWithinACStyleCommentQuery extends CharacterSequenceUsedWithinACStyleCommentSharedQuery +{ + SlashStarUsedWithinACStyleCommentQuery() { + this = CommentsPackage::slashStarUsedWithinACStyleCommentQuery() + } +} diff --git a/cpp/autosar/src/rules/M27-0-1/CstdioFunctionsUsed.ql b/cpp/autosar/src/rules/M27-0-1/CstdioFunctionsUsed.ql index 55254581a6..5656fc2edf 100644 --- a/cpp/autosar/src/rules/M27-0-1/CstdioFunctionsUsed.ql +++ b/cpp/autosar/src/rules/M27-0-1/CstdioFunctionsUsed.ql @@ -17,26 +17,8 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.cstdiofunctionsused.CstdioFunctionsUsed -from FunctionCall fc, Function f -where - not isExcluded(fc, BannedLibrariesPackage::cstdioFunctionsUsedQuery()) and - f = fc.getTarget() and - f.hasGlobalOrStdName([ - "remove", "rename", "tmpfile", "tmpnam", - // File access - "fclose", "fflush", "fopen", "freopen", "setbuf", "setvbuf", - // Formatted input/output - "fprintf", "fscanf", "printf", "scanf", "snprintf", "sprintf", "sscanf", "vfprintf", - "vfscanf", "vprintf", "vscanf", "vsnprintf", "vsprintf", "vsscanf", - // Character input/output - "fgetc", "fgets", "fputc", "fputs", "getc", "getchar", "gets", "putc", "putchar", "puts", - "ungetc", - // Direct input/output - "fread", "fwrite", - // File positioning - "fgetpos", "fseek", "fsetpos", "ftell", "rewind", - // Error handling - "clearerr", "feof", "ferror", "perror" - ]) -select fc, "Use of function '" + f.getQualifiedName() + "'." +class CstdioFunctionsUsedQuery extends CstdioFunctionsUsedSharedQuery { + CstdioFunctionsUsedQuery() { this = BannedLibrariesPackage::cstdioFunctionsUsedQuery() } +} diff --git a/cpp/autosar/src/rules/M27-0-1/CstdioMacrosUsed.ql b/cpp/autosar/src/rules/M27-0-1/CstdioMacrosUsed.ql index ccf633488e..311baeb195 100644 --- a/cpp/autosar/src/rules/M27-0-1/CstdioMacrosUsed.ql +++ b/cpp/autosar/src/rules/M27-0-1/CstdioMacrosUsed.ql @@ -17,12 +17,8 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.cstdiomacrosused.CstdioMacrosUsed -from MacroInvocation mi -where - not isExcluded(mi, BannedLibrariesPackage::cstdioMacrosUsedQuery()) and - mi.getMacroName() in [ - "BUFSIZ", "EOF", "FILENAME_MAX", "FOPEN_MAX", "L_tmpnam", "TMP_MAX", "_IOFBF", "IOLBF", - "_IONBF", "SEEK_CUR", "SEEK_END", "SEEK_SET" - ] -select mi, "Use of macro '" + mi.getMacroName() + "'." +class CstdioMacrosUsedQuery extends CstdioMacrosUsedSharedQuery { + CstdioMacrosUsedQuery() { this = BannedLibrariesPackage::cstdioMacrosUsedQuery() } +} diff --git a/cpp/autosar/src/rules/M27-0-1/CstdioTypesUsed.ql b/cpp/autosar/src/rules/M27-0-1/CstdioTypesUsed.ql index 6fc2adaffb..3a1f647c22 100644 --- a/cpp/autosar/src/rules/M27-0-1/CstdioTypesUsed.ql +++ b/cpp/autosar/src/rules/M27-0-1/CstdioTypesUsed.ql @@ -17,10 +17,8 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.cstdiotypesused.CstdioTypesUsed -from TypeMention tm, UserType ut -where - not isExcluded(tm, BannedLibrariesPackage::cstdioTypesUsedQuery()) and - ut = tm.getMentionedType() and - ut.hasGlobalOrStdName(["FILE", "fpos_t"]) -select tm, "Use of type '" + ut.getQualifiedName() + "'." +class CstdioTypesUsedQuery extends CstdioTypesUsedSharedQuery { + CstdioTypesUsedQuery() { this = BannedLibrariesPackage::cstdioTypesUsedQuery() } +} diff --git a/cpp/autosar/src/rules/M5-2-12/IdentifierWithArrayTypePassedAsFunctionArgumentDecayToAPointer.ql b/cpp/autosar/src/rules/M5-2-12/IdentifierWithArrayTypePassedAsFunctionArgumentDecayToAPointer.ql index 4207b4d56c..943fc026e8 100644 --- a/cpp/autosar/src/rules/M5-2-12/IdentifierWithArrayTypePassedAsFunctionArgumentDecayToAPointer.ql +++ b/cpp/autosar/src/rules/M5-2-12/IdentifierWithArrayTypePassedAsFunctionArgumentDecayToAPointer.ql @@ -15,33 +15,11 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.arraypassedasfunctionargumentdecaytoapointer.ArrayPassedAsFunctionArgumentDecayToAPointer -predicate arrayToPointerDecay(Access ae, Parameter p) { - ( - p.getType() instanceof PointerType and - // exclude parameters of void* because then it assumed the caller can pass in dimensions through other means. - // examples are uses in `memset` or `memcpy` - not p.getType() instanceof VoidPointerType - or - p.getType() instanceof ArrayType - ) and - ae.getType() instanceof ArrayType and - // exclude char[] arrays because we assume that we can determine its dimension by looking for a NULL byte. - not ae.getType().(ArrayType).getBaseType() instanceof CharType +class IdentifierWithArrayTypePassedAsFunctionArgumentDecayToAPointerQuery extends ArrayPassedAsFunctionArgumentDecayToAPointerSharedQuery +{ + IdentifierWithArrayTypePassedAsFunctionArgumentDecayToAPointerQuery() { + this = PointersPackage::identifierWithArrayTypePassedAsFunctionArgumentDecayToAPointerQuery() + } } - -from - FunctionCall fc, Function f, Parameter decayedArray, Variable array, VariableAccess arrayAccess, - int i -where - not isExcluded(fc, - PointersPackage::identifierWithArrayTypePassedAsFunctionArgumentDecayToAPointerQuery()) and - arrayAccess = array.getAnAccess() and - f = fc.getTarget() and - arrayAccess = fc.getArgument(i) and - decayedArray = f.getParameter(i) and - arrayToPointerDecay(arrayAccess, decayedArray) and - not arrayAccess.isAffectedByMacro() -select fc.getArgument(i), - "The array $@ decays to the pointer $@ when passed as an argument to the function $@.", array, - array.getName(), decayedArray, decayedArray.getName(), f, f.getName() diff --git a/cpp/autosar/src/rules/M5-2-6/CastNotConvertPointerToFunction.ql b/cpp/autosar/src/rules/M5-2-6/CastNotConvertPointerToFunction.ql index b6a51dc0ab..5a8df45ab1 100644 --- a/cpp/autosar/src/rules/M5-2-6/CastNotConvertPointerToFunction.ql +++ b/cpp/autosar/src/rules/M5-2-6/CastNotConvertPointerToFunction.ql @@ -15,11 +15,11 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.castsbetweenapointertofunctionandanyothertype.CastsBetweenAPointerToFunctionAndAnyOtherType -from Cast c -where - not isExcluded(c, PointersPackage::castNotConvertPointerToFunctionQuery()) and - not c.isImplicit() and - not c.isAffectedByMacro() and - c.getExpr().getType() instanceof FunctionPointerType -select c, "Cast converting a pointer to function." +class CastNotConvertPointerToFunctionQuery extends CastsBetweenAPointerToFunctionAndAnyOtherTypeSharedQuery +{ + CastNotConvertPointerToFunctionQuery() { + this = PointersPackage::castNotConvertPointerToFunctionQuery() + } +} diff --git a/cpp/autosar/src/rules/M5-3-2/UnaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsigned.ql b/cpp/autosar/src/rules/M5-3-2/UnaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsigned.ql index 0367f0aebe..7017d5e7de 100644 --- a/cpp/autosar/src/rules/M5-3-2/UnaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsigned.ql +++ b/cpp/autosar/src/rules/M5-3-2/UnaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsigned.ql @@ -14,13 +14,12 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.builtinunaryoperatorappliedtounsignedexpression.BuiltInUnaryOperatorAppliedToUnsignedExpression -from UnaryMinusExpr e, IntegralType t -where - not isExcluded(e, - OperatorsPackage::unaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsignedQuery()) and - t = e.getOperand().getExplicitlyConverted().getType().getUnderlyingType() and - t.isUnsigned() and - not e.isAffectedByMacro() -select e.getOperand(), - "The unary minus operator shall not be applied to an expression whose underlying type is unsigned." +class UnaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsignedQuery extends BuiltInUnaryOperatorAppliedToUnsignedExpressionSharedQuery +{ + UnaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsignedQuery() { + this = + OperatorsPackage::unaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsignedQuery() + } +} diff --git a/cpp/autosar/src/rules/M5-3-3/UnaryOperatorOverloaded.ql b/cpp/autosar/src/rules/M5-3-3/UnaryOperatorOverloaded.ql index 7e9511cf7e..94f0bc6062 100644 --- a/cpp/autosar/src/rules/M5-3-3/UnaryOperatorOverloaded.ql +++ b/cpp/autosar/src/rules/M5-3-3/UnaryOperatorOverloaded.ql @@ -13,8 +13,8 @@ import cpp import codingstandards.cpp.autosar -import codingstandards.cpp.Operator +import codingstandards.cpp.rules.addressofoperatoroverloaded.AddressOfOperatorOverloaded -from UnaryAddressOfOperator o -where not isExcluded(o, OperatorsPackage::unaryOperatorOverloadedQuery()) -select o, "The unary & operator overloaded." +class UnaryOperatorOverloadedQuery extends AddressOfOperatorOverloadedSharedQuery { + UnaryOperatorOverloadedQuery() { this = OperatorsPackage::unaryOperatorOverloadedQuery() } +} diff --git a/cpp/autosar/src/rules/M6-3-1/LoopCompoundCondition.ql b/cpp/autosar/src/rules/M6-3-1/LoopCompoundCondition.ql index 1c6c0b980e..b3566a1e27 100644 --- a/cpp/autosar/src/rules/M6-3-1/LoopCompoundCondition.ql +++ b/cpp/autosar/src/rules/M6-3-1/LoopCompoundCondition.ql @@ -16,9 +16,8 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.loopcompoundcondition.LoopCompoundCondition -from Loop loop -where - not isExcluded(loop, ConditionalsPackage::loopCompoundConditionQuery()) and - not loop.getStmt() instanceof BlockStmt -select loop, "Loop body not enclosed within braces." +class LoopCompoundConditionQuery extends LoopCompoundConditionSharedQuery { + LoopCompoundConditionQuery() { this = ConditionalsPackage::loopCompoundConditionQuery() } +} diff --git a/cpp/autosar/src/rules/M6-3-1/SwitchCompoundCondition.ql b/cpp/autosar/src/rules/M6-3-1/SwitchCompoundCondition.ql index ee83f44ccf..f550a456dc 100644 --- a/cpp/autosar/src/rules/M6-3-1/SwitchCompoundCondition.ql +++ b/cpp/autosar/src/rules/M6-3-1/SwitchCompoundCondition.ql @@ -16,36 +16,8 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.switchcompoundcondition.SwitchCompoundCondition -/** - * Class to differentiate between extractor generated blockstmt and actual blockstmt. The extractor - * will generate an artificial blockstmt when there is a single case and statement, e.g. - * ``` - * switch(x) - * case 1: - * f(); - * ``` - * This is because our AST model considers the `case` to be a statement in its own right, so the - * extractor needs an aritifical block to hold both the case and the statement. - */ -class ArtificialBlock extends BlockStmt { - ArtificialBlock() { - exists(Location block, Location firstStatement | - block = getLocation() and firstStatement = getStmt(0).getLocation() - | - // We can identify artificial blocks as those where the start of the statement is at the same - // location as the start of the first statement in the block i.e. there was no opening brace. - block.getStartLine() = firstStatement.getStartLine() and - block.getStartColumn() = firstStatement.getStartColumn() - ) - } +class SwitchCompoundConditionQuery extends SwitchCompoundConditionSharedQuery { + SwitchCompoundConditionQuery() { this = ConditionalsPackage::switchCompoundConditionQuery() } } - -from SwitchStmt switch -where - not isExcluded(switch, ConditionalsPackage::switchCompoundConditionQuery()) and - ( - switch.getStmt() instanceof ArtificialBlock or - not switch.getStmt() instanceof BlockStmt - ) -select switch, "Switch body not enclosed within braces." diff --git a/cpp/autosar/src/rules/M7-3-1/GlobalNamespaceMembershipViolation.ql b/cpp/autosar/src/rules/M7-3-1/GlobalNamespaceMembershipViolation.ql index cb714a65f2..e359880027 100644 --- a/cpp/autosar/src/rules/M7-3-1/GlobalNamespaceMembershipViolation.ql +++ b/cpp/autosar/src/rules/M7-3-1/GlobalNamespaceMembershipViolation.ql @@ -16,13 +16,10 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.globalnamespacedeclarations.GlobalNamespaceDeclarations -from DeclarationEntry de -where - not isExcluded(de, ScopePackage::globalNamespaceMembershipViolationQuery()) and - de.getDeclaration().getNamespace() instanceof GlobalNamespace and - de.getDeclaration().isTopLevel() and - not exists(Function f | f = de.getDeclaration() | f.hasGlobalName("main") or f.hasCLinkage()) -select de, - "Declaration " + de.getName() + - " is in the global namespace and is not a main, a namespace, or an extern \"C\" declaration." +class GlobalNamespaceMembershipViolationQuery extends GlobalNamespaceDeclarationsSharedQuery { + GlobalNamespaceMembershipViolationQuery() { + this = ScopePackage::globalNamespaceMembershipViolationQuery() + } +} diff --git a/cpp/autosar/src/rules/M7-3-2/IdentifierMainUsedForAFunctionOtherThanTheGlobalFunctionMain.ql b/cpp/autosar/src/rules/M7-3-2/IdentifierMainUsedForAFunctionOtherThanTheGlobalFunctionMain.ql index 9d86bd3637..25a01c66f8 100644 --- a/cpp/autosar/src/rules/M7-3-2/IdentifierMainUsedForAFunctionOtherThanTheGlobalFunctionMain.ql +++ b/cpp/autosar/src/rules/M7-3-2/IdentifierMainUsedForAFunctionOtherThanTheGlobalFunctionMain.ql @@ -15,11 +15,11 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.nonglobalfunctionmain.NonGlobalFunctionMain -from Function f -where - not isExcluded(f, - NamingPackage::identifierMainUsedForAFunctionOtherThanTheGlobalFunctionMainQuery()) and - f.hasName("main") and - not f.hasGlobalName("main") -select f, "Identifier main used for a function other than the global function main." +class IdentifierMainUsedForAFunctionOtherThanTheGlobalFunctionMainQuery extends NonGlobalFunctionMainSharedQuery +{ + IdentifierMainUsedForAFunctionOtherThanTheGlobalFunctionMainQuery() { + this = NamingPackage::identifierMainUsedForAFunctionOtherThanTheGlobalFunctionMainQuery() + } +} diff --git a/cpp/autosar/src/rules/M7-5-1/FunctionReturnAutomaticVarCondition.ql b/cpp/autosar/src/rules/M7-5-1/FunctionReturnAutomaticVarCondition.ql index e35858f40b..cb5aa9d105 100644 --- a/cpp/autosar/src/rules/M7-5-1/FunctionReturnAutomaticVarCondition.ql +++ b/cpp/autosar/src/rules/M7-5-1/FunctionReturnAutomaticVarCondition.ql @@ -16,19 +16,11 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.returnreferenceorpointertoautomaticlocalvariable.ReturnReferenceOrPointerToAutomaticLocalVariable -from ReturnStmt rs, StackVariable auto, Function f, VariableAccess va, string returnType -where - f = rs.getEnclosingFunction() and - ( - f.getType() instanceof ReferenceType and va = rs.getExpr() and returnType = "reference" - or - f.getType() instanceof PointerType and - va = rs.getExpr().(AddressOfExpr).getOperand() and - returnType = "pointer" - ) and - auto = va.getTarget() and - not auto.isStatic() and - not f.isCompilerGenerated() and - not auto.getType() instanceof ReferenceType -select rs, "The $@ returns a " + returnType + "to an $@ variable", f, f.getName(), auto, "automatic" +class FunctionReturnAutomaticVarConditionQuery extends ReturnReferenceOrPointerToAutomaticLocalVariableSharedQuery +{ + FunctionReturnAutomaticVarConditionQuery() { + this = FunctionsPackage::functionReturnAutomaticVarConditionQuery() + } +} diff --git a/cpp/autosar/src/rules/M8-0-1/MultipleGlobalOrMemberDeclarators.ql b/cpp/autosar/src/rules/M8-0-1/MultipleGlobalOrMemberDeclarators.ql index 8d16fccd94..c152821ab2 100644 --- a/cpp/autosar/src/rules/M8-0-1/MultipleGlobalOrMemberDeclarators.ql +++ b/cpp/autosar/src/rules/M8-0-1/MultipleGlobalOrMemberDeclarators.ql @@ -16,57 +16,10 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.multipleglobalormemberdeclarators.MultipleGlobalOrMemberDeclarators -/* - * Unfortunately, we do not have an equivalent of `DeclStmt` for non-local declarations, so we - * cannot determine whether a declaration was declared with another declaration. - * - * However, we can use location trickery to figure out if the declaration occurs close enough to - * another declaration that it _must_ have been declared within the same declaration sequence. - * - * We do this by requiring that the end location of a previous declaration is within a certain - * number of characters of the start location of the current declaration. - */ - -/** - * A `Declaration` which is not in a local scope, and is written directly by the user. - * - * These act as "candidates" for declarations that could plausibly occur in a declaration sequence - * with other candidates. - */ -class NonLocalUserDeclaration extends Declaration { - NonLocalUserDeclaration() { - not this instanceof StackVariable and - not this instanceof TemplateParameter and - not this instanceof EnumConstant and - not this instanceof TypedefType and - not any(LambdaCapture lc).getField() = this and - not this.(Function).isCompilerGenerated() and - not this.(Variable).isCompilerGenerated() and - not this.(Parameter).getFunction().isCompilerGenerated() and - not this.isInMacroExpansion() and - not exists(Struct s, TypedefType t | - s.isAnonymous() and - t.getBaseType() = s and - this = s.getAMemberVariable() - ) +class MultipleGlobalOrMemberDeclaratorsQuery extends MultipleGlobalOrMemberDeclaratorsSharedQuery { + MultipleGlobalOrMemberDeclaratorsQuery() { + this = InitializationPackage::multipleGlobalOrMemberDeclaratorsQuery() } } - -/** - * Holds if `d1` is followed directly by `d2`. - */ -predicate isFollowingDeclaration(NonLocalUserDeclaration d1, NonLocalUserDeclaration d2) { - exists(string filepath, int startline, int startcolumn, int endline, int endcolumn | - d1.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and - d2.getLocation().hasLocationInfo(filepath, startline, endcolumn + [2 .. 3], endline, _) - ) and - not d1.(UserType).stripType() = d2.(Variable).getType().stripType() -} - -from NonLocalUserDeclaration d1 -where - not isExcluded(d1, InitializationPackage::multipleGlobalOrMemberDeclaratorsQuery()) and - isFollowingDeclaration(d1, _) and - not isFollowingDeclaration(_, d1) -select d1, "Multiple declarations after " + d1.getName() + " in this declaration sequence." diff --git a/cpp/autosar/src/rules/M8-0-1/MultipleLocalDeclarators.ql b/cpp/autosar/src/rules/M8-0-1/MultipleLocalDeclarators.ql index 7545315b7e..6198ab7a5a 100644 --- a/cpp/autosar/src/rules/M8-0-1/MultipleLocalDeclarators.ql +++ b/cpp/autosar/src/rules/M8-0-1/MultipleLocalDeclarators.ql @@ -16,11 +16,8 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.multiplelocaldeclarators.MultipleLocalDeclarators -from DeclStmt ds -where - not isExcluded(ds, InitializationPackage::multipleLocalDeclaratorsQuery()) and - count(Declaration d | d = ds.getADeclaration()) > 1 and - // Not a compiler generated `DeclStmt`, such as in the range-based for loop - not ds.isCompilerGenerated() -select ds, "Declaration list contains more than one declaration." +class MultipleLocalDeclaratorsQuery extends MultipleLocalDeclaratorsSharedQuery { + MultipleLocalDeclaratorsQuery() { this = InitializationPackage::multipleLocalDeclaratorsQuery() } +} diff --git a/cpp/autosar/src/rules/M8-3-1/VirtualFunctionParametersUseTheSameDefaultArguments.ql b/cpp/autosar/src/rules/M8-3-1/VirtualFunctionParametersUseTheSameDefaultArguments.ql index 9d2b2d2006..a0ef5143e9 100644 --- a/cpp/autosar/src/rules/M8-3-1/VirtualFunctionParametersUseTheSameDefaultArguments.ql +++ b/cpp/autosar/src/rules/M8-3-1/VirtualFunctionParametersUseTheSameDefaultArguments.ql @@ -16,29 +16,11 @@ import cpp import codingstandards.cpp.autosar +import codingstandards.cpp.rules.overridingshallspecifydifferentdefaultarguments.OverridingShallSpecifyDifferentDefaultArguments -from VirtualFunction f1, VirtualFunction f2 -where - not isExcluded(f1, - VirtualFunctionsPackage::virtualFunctionParametersUseTheSameDefaultArgumentsQuery()) and - not isExcluded(f2, - VirtualFunctionsPackage::virtualFunctionParametersUseTheSameDefaultArgumentsQuery()) and - f2 = f1.getAnOverridingFunction() and - exists(Parameter p1, Parameter p2 | - p1 = f1.getAParameter() and - p2 = f2.getParameter(p1.getIndex()) - | - if p1.hasInitializer() - then - // if there is no initializer - not p2.hasInitializer() - or - // if there is one and it doesn't match - not p1.getInitializer().getExpr().getValueText() = - p2.getInitializer().getExpr().getValueText() - else - // if p1 doesn't have an initializer p2 shouldn't either - p2.hasInitializer() - ) -select f2, "$@ does not have the same default parameters as $@", f2, "overriding function", f1, - "overridden function" +class VirtualFunctionParametersUseTheSameDefaultArgumentsQuery extends OverridingShallSpecifyDifferentDefaultArgumentsSharedQuery +{ + VirtualFunctionParametersUseTheSameDefaultArgumentsQuery() { + this = VirtualFunctionsPackage::virtualFunctionParametersUseTheSameDefaultArgumentsQuery() + } +} diff --git a/cpp/autosar/src/rules/M9-6-4/NamedBitFieldsWithSignedIntegerTypeShallHaveALengthOfMoreThanOneBit.ql b/cpp/autosar/src/rules/M9-6-4/NamedBitFieldsWithSignedIntegerTypeShallHaveALengthOfMoreThanOneBit.ql index 7748f26ec1..96e434633e 100644 --- a/cpp/autosar/src/rules/M9-6-4/NamedBitFieldsWithSignedIntegerTypeShallHaveALengthOfMoreThanOneBit.ql +++ b/cpp/autosar/src/rules/M9-6-4/NamedBitFieldsWithSignedIntegerTypeShallHaveALengthOfMoreThanOneBit.ql @@ -22,4 +22,4 @@ where bf.getType().getUnderlyingType().(IntegralType).isSigned() and bf.getNumBits() < 2 and bf.getName() != "(unnamed bitfield)" -select bf, "A named bit-field with signed integral type should have at least 2 bits of storage " +select bf, "A named bit-field with signed integral type should have at least 2 bits of storage." diff --git a/cpp/autosar/test/rules/A12-1-1/ExplicitConstructorBaseClassInitialization.qlref b/cpp/autosar/test/rules/A12-1-1/ExplicitConstructorBaseClassInitialization.qlref deleted file mode 100644 index 9d356add77..0000000000 --- a/cpp/autosar/test/rules/A12-1-1/ExplicitConstructorBaseClassInitialization.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A12-1-1/ExplicitConstructorBaseClassInitialization.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A12-1-1/ExplicitConstructorBaseClassInitialization.testref b/cpp/autosar/test/rules/A12-1-1/ExplicitConstructorBaseClassInitialization.testref new file mode 100644 index 0000000000..ac8c5e1a83 --- /dev/null +++ b/cpp/autosar/test/rules/A12-1-1/ExplicitConstructorBaseClassInitialization.testref @@ -0,0 +1 @@ +cpp/common/test/rules/initializeallvirtualbaseclasses/InitializeAllVirtualBaseClasses.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A12-8-5/CopyAssignmentAndAMoveHandleSelfAssignment.qlref b/cpp/autosar/test/rules/A12-8-5/CopyAssignmentAndAMoveHandleSelfAssignment.qlref deleted file mode 100644 index 686462e15f..0000000000 --- a/cpp/autosar/test/rules/A12-8-5/CopyAssignmentAndAMoveHandleSelfAssignment.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A12-8-5/CopyAssignmentAndAMoveHandleSelfAssignment.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A12-8-5/CopyAssignmentAndAMoveHandleSelfAssignment.testref b/cpp/autosar/test/rules/A12-8-5/CopyAssignmentAndAMoveHandleSelfAssignment.testref new file mode 100644 index 0000000000..65fc614121 --- /dev/null +++ b/cpp/autosar/test/rules/A12-8-5/CopyAssignmentAndAMoveHandleSelfAssignment.testref @@ -0,0 +1 @@ +cpp/common/test/rules/copyandmoveassignmentsshallhandleselfassignment/CopyAndMoveAssignmentsShallHandleSelfAssignment.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A14-8-2/ExplicitSpecializationsOfFunctionTemplatesUsed.qlref b/cpp/autosar/test/rules/A14-8-2/ExplicitSpecializationsOfFunctionTemplatesUsed.qlref deleted file mode 100644 index b2f19b3af3..0000000000 --- a/cpp/autosar/test/rules/A14-8-2/ExplicitSpecializationsOfFunctionTemplatesUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A14-8-2/ExplicitSpecializationsOfFunctionTemplatesUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A14-8-2/ExplicitSpecializationsOfFunctionTemplatesUsed.testref b/cpp/autosar/test/rules/A14-8-2/ExplicitSpecializationsOfFunctionTemplatesUsed.testref new file mode 100644 index 0000000000..6a284e2cbb --- /dev/null +++ b/cpp/autosar/test/rules/A14-8-2/ExplicitSpecializationsOfFunctionTemplatesUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/functiontemplatesexplicitlyspecialized/FunctionTemplatesExplicitlySpecialized.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A15-1-2/PointerExceptionObject.qlref b/cpp/autosar/test/rules/A15-1-2/PointerExceptionObject.qlref deleted file mode 100644 index 68c8e7af9a..0000000000 --- a/cpp/autosar/test/rules/A15-1-2/PointerExceptionObject.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A15-1-2/PointerExceptionObject.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A15-1-2/PointerExceptionObject.testref b/cpp/autosar/test/rules/A15-1-2/PointerExceptionObject.testref new file mode 100644 index 0000000000..24d4229225 --- /dev/null +++ b/cpp/autosar/test/rules/A15-1-2/PointerExceptionObject.testref @@ -0,0 +1 @@ +cpp/common/test/rules/exceptionobjecthavepointertype/ExceptionObjectHavePointerType.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A15-4-2/NoExceptFunctionThrows.qlref b/cpp/autosar/test/rules/A15-4-2/NoExceptFunctionThrows.qlref deleted file mode 100644 index 80fbc7365c..0000000000 --- a/cpp/autosar/test/rules/A15-4-2/NoExceptFunctionThrows.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A15-4-2/NoExceptFunctionThrows.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A15-4-2/NoExceptFunctionThrows.testref b/cpp/autosar/test/rules/A15-4-2/NoExceptFunctionThrows.testref new file mode 100644 index 0000000000..76dc55827f --- /dev/null +++ b/cpp/autosar/test/rules/A15-4-2/NoExceptFunctionThrows.testref @@ -0,0 +1 @@ +cpp/common/test/rules/noexceptfunctionshouldnotpropagatetothecaller/NoexceptFunctionShouldNotPropagateToTheCaller.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A18-1-2/VectorboolSpecializationUsed.qlref b/cpp/autosar/test/rules/A18-1-2/VectorboolSpecializationUsed.qlref deleted file mode 100644 index 9f78cda4c6..0000000000 --- a/cpp/autosar/test/rules/A18-1-2/VectorboolSpecializationUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A18-1-2/VectorboolSpecializationUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A18-1-2/VectorboolSpecializationUsed.testref b/cpp/autosar/test/rules/A18-1-2/VectorboolSpecializationUsed.testref new file mode 100644 index 0000000000..a934690acb --- /dev/null +++ b/cpp/autosar/test/rules/A18-1-2/VectorboolSpecializationUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/vectorshouldnotbespecializedwithbool/VectorShouldNotBeSpecializedWithBool.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A18-5-4/GlobalSizedOperatorDeleteNotDefined.qlref b/cpp/autosar/test/rules/A18-5-4/GlobalSizedOperatorDeleteNotDefined.qlref deleted file mode 100644 index 1f1e8258e4..0000000000 --- a/cpp/autosar/test/rules/A18-5-4/GlobalSizedOperatorDeleteNotDefined.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A18-5-4/GlobalSizedOperatorDeleteNotDefined.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A18-5-4/GlobalSizedOperatorDeleteNotDefined.testref b/cpp/autosar/test/rules/A18-5-4/GlobalSizedOperatorDeleteNotDefined.testref new file mode 100644 index 0000000000..4d1e21d4cb --- /dev/null +++ b/cpp/autosar/test/rules/A18-5-4/GlobalSizedOperatorDeleteNotDefined.testref @@ -0,0 +1 @@ +cpp/common/test/rules/globalsizedoperatordeletenotdefined/GlobalSizedOperatorDeleteNotDefined.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A18-5-4/GlobalUnsizedOperatorDeleteNotDefined.qlref b/cpp/autosar/test/rules/A18-5-4/GlobalUnsizedOperatorDeleteNotDefined.qlref deleted file mode 100644 index 04cc5622dd..0000000000 --- a/cpp/autosar/test/rules/A18-5-4/GlobalUnsizedOperatorDeleteNotDefined.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A18-5-4/GlobalUnsizedOperatorDeleteNotDefined.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A18-5-4/GlobalUnsizedOperatorDeleteNotDefined.testref b/cpp/autosar/test/rules/A18-5-4/GlobalUnsizedOperatorDeleteNotDefined.testref new file mode 100644 index 0000000000..f2fcc2eded --- /dev/null +++ b/cpp/autosar/test/rules/A18-5-4/GlobalUnsizedOperatorDeleteNotDefined.testref @@ -0,0 +1 @@ +cpp/common/test/rules/globalunsizedoperatordeletenotdefined/GlobalUnsizedOperatorDeleteNotDefined.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A18-9-2/ForwardingValuesToOtherFunctions.qlref b/cpp/autosar/test/rules/A18-9-2/ForwardingValuesToOtherFunctions.qlref deleted file mode 100644 index 05bcab607a..0000000000 --- a/cpp/autosar/test/rules/A18-9-2/ForwardingValuesToOtherFunctions.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A18-9-2/ForwardingValuesToOtherFunctions.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A18-9-2/ForwardingValuesToOtherFunctions.testref b/cpp/autosar/test/rules/A18-9-2/ForwardingValuesToOtherFunctions.testref new file mode 100644 index 0000000000..d56acb8415 --- /dev/null +++ b/cpp/autosar/test/rules/A18-9-2/ForwardingValuesToOtherFunctions.testref @@ -0,0 +1 @@ +cpp/common/test/rules/forwardingreferencesandforwardnotusedtogether/ForwardingReferencesAndForwardNotUsedTogether.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A2-13-1/EscapeSequenceOutsideISO.qlref b/cpp/autosar/test/rules/A2-13-1/EscapeSequenceOutsideISO.qlref deleted file mode 100644 index ce6347c955..0000000000 --- a/cpp/autosar/test/rules/A2-13-1/EscapeSequenceOutsideISO.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A2-13-1/EscapeSequenceOutsideISO.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A2-13-1/EscapeSequenceOutsideISO.testref b/cpp/autosar/test/rules/A2-13-1/EscapeSequenceOutsideISO.testref new file mode 100644 index 0000000000..924122e38e --- /dev/null +++ b/cpp/autosar/test/rules/A2-13-1/EscapeSequenceOutsideISO.testref @@ -0,0 +1 @@ +cpp/common/test/rules/backslashcharactermisuse/BackslashCharacterMisuse.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A2-7-1/SingleLineCommentEndsWithSlash.qlref b/cpp/autosar/test/rules/A2-7-1/SingleLineCommentEndsWithSlash.qlref deleted file mode 100644 index 876f24be61..0000000000 --- a/cpp/autosar/test/rules/A2-7-1/SingleLineCommentEndsWithSlash.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A2-7-1/SingleLineCommentEndsWithSlash.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A2-7-1/SingleLineCommentEndsWithSlash.testref b/cpp/autosar/test/rules/A2-7-1/SingleLineCommentEndsWithSlash.testref new file mode 100644 index 0000000000..7874a476a0 --- /dev/null +++ b/cpp/autosar/test/rules/A2-7-1/SingleLineCommentEndsWithSlash.testref @@ -0,0 +1 @@ +cpp/common/test/rules/linesplicingusedincomments/LineSplicingUsedInComments.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A4-10-1/NullPointerConstantNotNullptr.qlref b/cpp/autosar/test/rules/A4-10-1/NullPointerConstantNotNullptr.qlref deleted file mode 100644 index d836b834b3..0000000000 --- a/cpp/autosar/test/rules/A4-10-1/NullPointerConstantNotNullptr.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A4-10-1/NullPointerConstantNotNullptr.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A4-10-1/NullPointerConstantNotNullptr.testref b/cpp/autosar/test/rules/A4-10-1/NullPointerConstantNotNullptr.testref new file mode 100644 index 0000000000..aeb655a341 --- /dev/null +++ b/cpp/autosar/test/rules/A4-10-1/NullPointerConstantNotNullptr.testref @@ -0,0 +1 @@ +cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A5-10-1/PointerToMemberVirtualFunctionWithNullPointerConstant.qlref b/cpp/autosar/test/rules/A5-10-1/PointerToMemberVirtualFunctionWithNullPointerConstant.qlref deleted file mode 100644 index 5f588b44ab..0000000000 --- a/cpp/autosar/test/rules/A5-10-1/PointerToMemberVirtualFunctionWithNullPointerConstant.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A5-10-1/PointerToMemberVirtualFunctionWithNullPointerConstant.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A5-10-1/PointerToMemberVirtualFunctionWithNullPointerConstant.testref b/cpp/autosar/test/rules/A5-10-1/PointerToMemberVirtualFunctionWithNullPointerConstant.testref new file mode 100644 index 0000000000..ca8eab9681 --- /dev/null +++ b/cpp/autosar/test/rules/A5-10-1/PointerToMemberVirtualFunctionWithNullPointerConstant.testref @@ -0,0 +1 @@ +cpp/common/test/rules/potentiallyvirtualpointeronlycomparestonullptr/PotentiallyVirtualPointerOnlyComparesToNullptr.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A5-10-1/PotentiallyVirtualPointerOnlyComparesToNullptr.testref b/cpp/autosar/test/rules/A5-10-1/PotentiallyVirtualPointerOnlyComparesToNullptr.testref new file mode 100644 index 0000000000..ca8eab9681 --- /dev/null +++ b/cpp/autosar/test/rules/A5-10-1/PotentiallyVirtualPointerOnlyComparesToNullptr.testref @@ -0,0 +1 @@ +cpp/common/test/rules/potentiallyvirtualpointeronlycomparestonullptr/PotentiallyVirtualPointerOnlyComparesToNullptr.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A5-2-4/ReinterpretCastUsed.qlref b/cpp/autosar/test/rules/A5-2-4/ReinterpretCastUsed.qlref deleted file mode 100644 index 3cfb0444cc..0000000000 --- a/cpp/autosar/test/rules/A5-2-4/ReinterpretCastUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A5-2-4/ReinterpretCastUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A5-2-4/ReinterpretCastUsed.testref b/cpp/autosar/test/rules/A5-2-4/ReinterpretCastUsed.testref new file mode 100644 index 0000000000..81f18c2d9c --- /dev/null +++ b/cpp/autosar/test/rules/A5-2-4/ReinterpretCastUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/reinterpretcastused/ReinterpretCastUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A6-6-1/GotoStatementUsed.expected b/cpp/autosar/test/rules/A6-6-1/GotoStatementUsed.expected deleted file mode 100644 index 9f4343cf1c..0000000000 --- a/cpp/autosar/test/rules/A6-6-1/GotoStatementUsed.expected +++ /dev/null @@ -1 +0,0 @@ -| test.cpp:4:3:4:14 | goto ... | Use of goto. | diff --git a/cpp/autosar/test/rules/A6-6-1/GotoStatementUsed.qlref b/cpp/autosar/test/rules/A6-6-1/GotoStatementUsed.qlref deleted file mode 100644 index d3516aa03b..0000000000 --- a/cpp/autosar/test/rules/A6-6-1/GotoStatementUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A6-6-1/GotoStatementUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A6-6-1/GotoStatementUsed.testref b/cpp/autosar/test/rules/A6-6-1/GotoStatementUsed.testref new file mode 100644 index 0000000000..44d306f80c --- /dev/null +++ b/cpp/autosar/test/rules/A6-6-1/GotoStatementUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A6-6-1/test.cpp b/cpp/autosar/test/rules/A6-6-1/test.cpp deleted file mode 100644 index d13f01961c..0000000000 --- a/cpp/autosar/test/rules/A6-6-1/test.cpp +++ /dev/null @@ -1,9 +0,0 @@ -void test_goto() { - int x = 1; - - goto label1; // NON_COMPLIANT - -label1: - - x = 2; -} \ No newline at end of file diff --git a/cpp/autosar/test/rules/A7-2-2/EnumerationUnderlyingBaseTypeNotExplicitlyDefined.qlref b/cpp/autosar/test/rules/A7-2-2/EnumerationUnderlyingBaseTypeNotExplicitlyDefined.qlref deleted file mode 100644 index 1ed510a506..0000000000 --- a/cpp/autosar/test/rules/A7-2-2/EnumerationUnderlyingBaseTypeNotExplicitlyDefined.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A7-2-2/EnumerationUnderlyingBaseTypeNotExplicitlyDefined.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A7-2-2/EnumerationUnderlyingBaseTypeNotExplicitlyDefined.testref b/cpp/autosar/test/rules/A7-2-2/EnumerationUnderlyingBaseTypeNotExplicitlyDefined.testref new file mode 100644 index 0000000000..d7a73fd488 --- /dev/null +++ b/cpp/autosar/test/rules/A7-2-2/EnumerationUnderlyingBaseTypeNotExplicitlyDefined.testref @@ -0,0 +1 @@ +cpp/common/test/rules/enumerationnotdefinedwithanexplicitunderlyingtype/EnumerationNotDefinedWithAnExplicitUnderlyingType.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A7-3-1/DefinitionNotConsideredForUnqualifiedLookup.qlref b/cpp/autosar/test/rules/A7-3-1/DefinitionNotConsideredForUnqualifiedLookup.qlref deleted file mode 100644 index 0fe94e847c..0000000000 --- a/cpp/autosar/test/rules/A7-3-1/DefinitionNotConsideredForUnqualifiedLookup.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A7-3-1/DefinitionNotConsideredForUnqualifiedLookup.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A7-3-1/DefinitionNotConsideredForUnqualifiedLookup.testref b/cpp/autosar/test/rules/A7-3-1/DefinitionNotConsideredForUnqualifiedLookup.testref new file mode 100644 index 0000000000..7a5ae74d2e --- /dev/null +++ b/cpp/autosar/test/rules/A7-3-1/DefinitionNotConsideredForUnqualifiedLookup.testref @@ -0,0 +1 @@ +cpp/common/test/rules/definitionnotconsideredforunqualifiedlookup/DefinitionNotConsideredForUnqualifiedLookup.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A7-3-1/HiddenInheritedNonOverridableMemberFunction.qlref b/cpp/autosar/test/rules/A7-3-1/HiddenInheritedNonOverridableMemberFunction.qlref deleted file mode 100644 index d94c3c0b0a..0000000000 --- a/cpp/autosar/test/rules/A7-3-1/HiddenInheritedNonOverridableMemberFunction.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A7-3-1/HiddenInheritedNonOverridableMemberFunction.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A7-3-1/HiddenInheritedNonOverridableMemberFunction.testref b/cpp/autosar/test/rules/A7-3-1/HiddenInheritedNonOverridableMemberFunction.testref new file mode 100644 index 0000000000..2fb9608ee8 --- /dev/null +++ b/cpp/autosar/test/rules/A7-3-1/HiddenInheritedNonOverridableMemberFunction.testref @@ -0,0 +1 @@ +cpp/common/test/rules/hiddeninheritednonoverridablememberfunction/HiddenInheritedNonOverridableMemberFunction.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A7-3-1/HiddenInheritedOverridableMemberFunction.qlref b/cpp/autosar/test/rules/A7-3-1/HiddenInheritedOverridableMemberFunction.qlref deleted file mode 100644 index 57d16c4e90..0000000000 --- a/cpp/autosar/test/rules/A7-3-1/HiddenInheritedOverridableMemberFunction.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A7-3-1/HiddenInheritedOverridableMemberFunction.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A7-3-1/HiddenInheritedOverridableMemberFunction.testref b/cpp/autosar/test/rules/A7-3-1/HiddenInheritedOverridableMemberFunction.testref new file mode 100644 index 0000000000..e768ced8d3 --- /dev/null +++ b/cpp/autosar/test/rules/A7-3-1/HiddenInheritedOverridableMemberFunction.testref @@ -0,0 +1 @@ +cpp/common/test/rules/hiddeninheritedoverridablememberfunction/HiddenInheritedOverridableMemberFunction.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A7-4-1/AsmDeclarationUsed.qlref b/cpp/autosar/test/rules/A7-4-1/AsmDeclarationUsed.qlref deleted file mode 100644 index 286e62bd18..0000000000 --- a/cpp/autosar/test/rules/A7-4-1/AsmDeclarationUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A7-4-1/AsmDeclarationUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A7-4-1/AsmDeclarationUsed.testref b/cpp/autosar/test/rules/A7-4-1/AsmDeclarationUsed.testref new file mode 100644 index 0000000000..f643f6a9c7 --- /dev/null +++ b/cpp/autosar/test/rules/A7-4-1/AsmDeclarationUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/asmdeclarationused/AsmDeclarationUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A7-5-2/RecursiveFunctions.qlref b/cpp/autosar/test/rules/A7-5-2/RecursiveFunctions.qlref deleted file mode 100644 index 10fccea7f7..0000000000 --- a/cpp/autosar/test/rules/A7-5-2/RecursiveFunctions.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A7-5-2/RecursiveFunctions.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A7-5-2/RecursiveFunctions.testref b/cpp/autosar/test/rules/A7-5-2/RecursiveFunctions.testref new file mode 100644 index 0000000000..f459a29bf1 --- /dev/null +++ b/cpp/autosar/test/rules/A7-5-2/RecursiveFunctions.testref @@ -0,0 +1 @@ +cpp/common/test/rules/functionscallthemselveseitherdirectlyorindirectly/FunctionsCallThemselvesEitherDirectlyOrIndirectly.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A8-5-4/ConfusingUseOfInitializerListConstructors.qlref b/cpp/autosar/test/rules/A8-5-4/ConfusingUseOfInitializerListConstructors.qlref deleted file mode 100644 index eb351d9e36..0000000000 --- a/cpp/autosar/test/rules/A8-5-4/ConfusingUseOfInitializerListConstructors.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A8-5-4/ConfusingUseOfInitializerListConstructors.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A8-5-4/ConfusingUseOfInitializerListConstructors.testref b/cpp/autosar/test/rules/A8-5-4/ConfusingUseOfInitializerListConstructors.testref new file mode 100644 index 0000000000..49b73d06a9 --- /dev/null +++ b/cpp/autosar/test/rules/A8-5-4/ConfusingUseOfInitializerListConstructors.testref @@ -0,0 +1 @@ +cpp/common/test/rules/initializerlistconstructoristheonlyconstructor/InitializerListConstructorIsTheOnlyConstructor.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M10-1-3/AccessibleBaseClassBothVirtualAndNonVirtualInHierarchy.qlref b/cpp/autosar/test/rules/M10-1-3/AccessibleBaseClassBothVirtualAndNonVirtualInHierarchy.qlref deleted file mode 100644 index 208baa8d08..0000000000 --- a/cpp/autosar/test/rules/M10-1-3/AccessibleBaseClassBothVirtualAndNonVirtualInHierarchy.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M10-1-3/AccessibleBaseClassBothVirtualAndNonVirtualInHierarchy.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M10-1-3/AccessibleBaseClassBothVirtualAndNonVirtualInHierarchy.testref b/cpp/autosar/test/rules/M10-1-3/AccessibleBaseClassBothVirtualAndNonVirtualInHierarchy.testref new file mode 100644 index 0000000000..fe57c50fe3 --- /dev/null +++ b/cpp/autosar/test/rules/M10-1-3/AccessibleBaseClassBothVirtualAndNonVirtualInHierarchy.testref @@ -0,0 +1 @@ +cpp/common/test/rules/virtualandnonvirtualclassinthehierarchy/VirtualAndNonVirtualClassInTheHierarchy.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M12-1-1/DynamicTypeOfThisUsedFromConstructorOrDestructor.qlref b/cpp/autosar/test/rules/M12-1-1/DynamicTypeOfThisUsedFromConstructorOrDestructor.qlref deleted file mode 100644 index 4235959d77..0000000000 --- a/cpp/autosar/test/rules/M12-1-1/DynamicTypeOfThisUsedFromConstructorOrDestructor.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M12-1-1/DynamicTypeOfThisUsedFromConstructorOrDestructor.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M12-1-1/DynamicTypeOfThisUsedFromConstructorOrDestructor.testref b/cpp/autosar/test/rules/M12-1-1/DynamicTypeOfThisUsedFromConstructorOrDestructor.testref new file mode 100644 index 0000000000..596f74b010 --- /dev/null +++ b/cpp/autosar/test/rules/M12-1-1/DynamicTypeOfThisUsedFromConstructorOrDestructor.testref @@ -0,0 +1 @@ +cpp/common/test/rules/objectsdynamictypeusedfromconstructorordestructor/ObjectsDynamicTypeUsedFromConstructorOrDestructor.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThis.qlref b/cpp/autosar/test/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThis.qlref deleted file mode 100644 index f0e2ebd711..0000000000 --- a/cpp/autosar/test/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThis.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThis.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThis.testref b/cpp/autosar/test/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThis.testref new file mode 100644 index 0000000000..ad5590bc1f --- /dev/null +++ b/cpp/autosar/test/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThis.testref @@ -0,0 +1 @@ +cpp/common/test/rules/namenotreferredusingaqualifiedidorthis/NameNotReferredUsingAQualifiedIdOrThis.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThisAudit.qlref b/cpp/autosar/test/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThisAudit.qlref deleted file mode 100644 index 442eb62675..0000000000 --- a/cpp/autosar/test/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThisAudit.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThisAudit.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThisAudit.testref b/cpp/autosar/test/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThisAudit.testref new file mode 100644 index 0000000000..f7ff9100a6 --- /dev/null +++ b/cpp/autosar/test/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThisAudit.testref @@ -0,0 +1 @@ +cpp/common/test/rules/namenotreferredusingaqualifiedidorthisaudit/NameNotReferredUsingAQualifiedIdOrThisAudit.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M15-1-3/EmptyThrowOutsideCatch.qlref b/cpp/autosar/test/rules/M15-1-3/EmptyThrowOutsideCatch.qlref deleted file mode 100644 index 3643376e59..0000000000 --- a/cpp/autosar/test/rules/M15-1-3/EmptyThrowOutsideCatch.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M15-1-3/EmptyThrowOutsideCatch.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M15-1-3/EmptyThrowOutsideCatch.testref b/cpp/autosar/test/rules/M15-1-3/EmptyThrowOutsideCatch.testref new file mode 100644 index 0000000000..f3c961d8f1 --- /dev/null +++ b/cpp/autosar/test/rules/M15-1-3/EmptyThrowOutsideCatch.testref @@ -0,0 +1 @@ +cpp/common/test/rules/emptythrowonlywithinacatchhandler/EmptyThrowOnlyWithinACatchHandler.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.qlref b/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.qlref deleted file mode 100644 index a69e18549f..0000000000 --- a/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M18-2-1/MacroOffsetofUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.testref b/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.testref new file mode 100644 index 0000000000..022fef6071 --- /dev/null +++ b/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/macrooffsetofused/MacroOffsetofUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M18-7-1/CsignalFunctionsUsed.qlref b/cpp/autosar/test/rules/M18-7-1/CsignalFunctionsUsed.qlref deleted file mode 100644 index 445ccd5bd4..0000000000 --- a/cpp/autosar/test/rules/M18-7-1/CsignalFunctionsUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M18-7-1/CsignalFunctionsUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M18-7-1/CsignalFunctionsUsed.testref b/cpp/autosar/test/rules/M18-7-1/CsignalFunctionsUsed.testref new file mode 100644 index 0000000000..a09406a932 --- /dev/null +++ b/cpp/autosar/test/rules/M18-7-1/CsignalFunctionsUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/csignalfunctionsused/CsignalFunctionsUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M18-7-1/CsignalTypesUsed.qlref b/cpp/autosar/test/rules/M18-7-1/CsignalTypesUsed.qlref deleted file mode 100644 index 34c83d741a..0000000000 --- a/cpp/autosar/test/rules/M18-7-1/CsignalTypesUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M18-7-1/CsignalTypesUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M18-7-1/CsignalTypesUsed.testref b/cpp/autosar/test/rules/M18-7-1/CsignalTypesUsed.testref new file mode 100644 index 0000000000..3d398d799b --- /dev/null +++ b/cpp/autosar/test/rules/M18-7-1/CsignalTypesUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/csignaltypesused/CsignalTypesUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M2-13-2/UseOfNonZeroOctalEscape.expected b/cpp/autosar/test/rules/M2-13-2/UseOfNonZeroOctalEscape.expected index 17a0016fec..41ebcf7629 100644 --- a/cpp/autosar/test/rules/M2-13-2/UseOfNonZeroOctalEscape.expected +++ b/cpp/autosar/test/rules/M2-13-2/UseOfNonZeroOctalEscape.expected @@ -1,6 +1,6 @@ | test.cpp:3:3:3:8 | 10 | This literal contains the non-zero octal escape code \\012. | | test.cpp:4:3:4:8 | 44 | This literal contains the non-zero octal escape code \\054. | | test.cpp:5:3:5:9 | 3129 | This literal contains the non-zero octal escape code \\014. | -| test.cpp:10:3:10:8 | \n | This literal contains the non-zero octal escape code \\012. | -| test.cpp:11:3:11:8 | , | This literal contains the non-zero octal escape code \\054. | -| test.cpp:12:3:12:9 | \u000c9 | This literal contains the non-zero octal escape code \\014. | +| test.cpp:7:3:7:8 | \n | This literal contains the non-zero octal escape code \\012. | +| test.cpp:8:3:8:8 | , | This literal contains the non-zero octal escape code \\054. | +| test.cpp:9:3:9:9 | \u000c9 | This literal contains the non-zero octal escape code \\014. | diff --git a/cpp/autosar/test/rules/M2-13-2/UseOfNonZeroOctalLiteral.expected b/cpp/autosar/test/rules/M2-13-2/UseOfNonZeroOctalLiteral.expected deleted file mode 100644 index 8109c107a5..0000000000 --- a/cpp/autosar/test/rules/M2-13-2/UseOfNonZeroOctalLiteral.expected +++ /dev/null @@ -1,2 +0,0 @@ -| test.cpp:7:3:7:5 | 10 | Non zero octal literal 012. | -| test.cpp:8:3:8:5 | 44 | Non zero octal literal 054. | diff --git a/cpp/autosar/test/rules/M2-13-2/UseOfNonZeroOctalLiteral.qlref b/cpp/autosar/test/rules/M2-13-2/UseOfNonZeroOctalLiteral.qlref deleted file mode 100644 index 67900e54f7..0000000000 --- a/cpp/autosar/test/rules/M2-13-2/UseOfNonZeroOctalLiteral.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M2-13-2/UseOfNonZeroOctalLiteral.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M2-13-2/UseOfNonZeroOctalLiteral.testref b/cpp/autosar/test/rules/M2-13-2/UseOfNonZeroOctalLiteral.testref new file mode 100644 index 0000000000..97c466a866 --- /dev/null +++ b/cpp/autosar/test/rules/M2-13-2/UseOfNonZeroOctalLiteral.testref @@ -0,0 +1 @@ +cpp/common/test/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M2-13-2/test.cpp b/cpp/autosar/test/rules/M2-13-2/test.cpp index a89809d68c..3c7fba30dd 100644 --- a/cpp/autosar/test/rules/M2-13-2/test.cpp +++ b/cpp/autosar/test/rules/M2-13-2/test.cpp @@ -3,9 +3,6 @@ void test_non_zero_octal() { '\012'; // NON_COMPLIANT '\054'; // NON_COMPLIANT '\0149'; // NON_COMPLIANT - 0; // COMPLIANT - octal literal zero permitted - 012; // NON_COMPLIANT - 054; // NON_COMPLIANT "\0"; // COMPLIANT - octal zero escape sequence permitted "\012"; // NON_COMPLIANT "\054"; // NON_COMPLIANT diff --git a/cpp/autosar/test/rules/M2-13-3/MissingUSuffix.qlref b/cpp/autosar/test/rules/M2-13-3/MissingUSuffix.qlref deleted file mode 100644 index ffb71066d5..0000000000 --- a/cpp/autosar/test/rules/M2-13-3/MissingUSuffix.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M2-13-3/MissingUSuffix.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M2-13-3/MissingUSuffix.testref b/cpp/autosar/test/rules/M2-13-3/MissingUSuffix.testref new file mode 100644 index 0000000000..9133a84ce4 --- /dev/null +++ b/cpp/autosar/test/rules/M2-13-3/MissingUSuffix.testref @@ -0,0 +1 @@ +cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/UnsignedIntegerLiteralsNotAppropriatelySuffixed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M2-7-1/SlashStarUsedWithinACStyleComment.qlref b/cpp/autosar/test/rules/M2-7-1/SlashStarUsedWithinACStyleComment.qlref deleted file mode 100644 index 3f146ebeaf..0000000000 --- a/cpp/autosar/test/rules/M2-7-1/SlashStarUsedWithinACStyleComment.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M2-7-1/SlashStarUsedWithinACStyleComment.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M2-7-1/SlashStarUsedWithinACStyleComment.testref b/cpp/autosar/test/rules/M2-7-1/SlashStarUsedWithinACStyleComment.testref new file mode 100644 index 0000000000..971b1953f7 --- /dev/null +++ b/cpp/autosar/test/rules/M2-7-1/SlashStarUsedWithinACStyleComment.testref @@ -0,0 +1 @@ +cpp/common/test/rules/charactersequenceusedwithinacstylecomment/CharacterSequenceUsedWithinACStyleComment.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M27-0-1/CstdioFunctionsUsed.qlref b/cpp/autosar/test/rules/M27-0-1/CstdioFunctionsUsed.qlref deleted file mode 100644 index 7d97c146c9..0000000000 --- a/cpp/autosar/test/rules/M27-0-1/CstdioFunctionsUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M27-0-1/CstdioFunctionsUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M27-0-1/CstdioFunctionsUsed.testref b/cpp/autosar/test/rules/M27-0-1/CstdioFunctionsUsed.testref new file mode 100644 index 0000000000..5f8b3d8a9a --- /dev/null +++ b/cpp/autosar/test/rules/M27-0-1/CstdioFunctionsUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/cstdiofunctionsused/CstdioFunctionsUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M27-0-1/CstdioMacrosUsed.qlref b/cpp/autosar/test/rules/M27-0-1/CstdioMacrosUsed.qlref deleted file mode 100644 index 20bf876eba..0000000000 --- a/cpp/autosar/test/rules/M27-0-1/CstdioMacrosUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M27-0-1/CstdioMacrosUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M27-0-1/CstdioMacrosUsed.testref b/cpp/autosar/test/rules/M27-0-1/CstdioMacrosUsed.testref new file mode 100644 index 0000000000..a1ba376c3b --- /dev/null +++ b/cpp/autosar/test/rules/M27-0-1/CstdioMacrosUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/cstdiomacrosused/CstdioMacrosUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.qlref b/cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.qlref deleted file mode 100644 index 10beab7eaa..0000000000 --- a/cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M27-0-1/CstdioTypesUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.testref b/cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.testref new file mode 100644 index 0000000000..4c08a75cfe --- /dev/null +++ b/cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/cstdiotypesused/CstdioTypesUsed.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M5-2-12/IdentifierWithArrayTypePassedAsFunctionArgumentDecayToAPointer.qlref b/cpp/autosar/test/rules/M5-2-12/IdentifierWithArrayTypePassedAsFunctionArgumentDecayToAPointer.qlref deleted file mode 100644 index 3a513b4cbe..0000000000 --- a/cpp/autosar/test/rules/M5-2-12/IdentifierWithArrayTypePassedAsFunctionArgumentDecayToAPointer.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M5-2-12/IdentifierWithArrayTypePassedAsFunctionArgumentDecayToAPointer.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M5-2-12/IdentifierWithArrayTypePassedAsFunctionArgumentDecayToAPointer.testref b/cpp/autosar/test/rules/M5-2-12/IdentifierWithArrayTypePassedAsFunctionArgumentDecayToAPointer.testref new file mode 100644 index 0000000000..06f2ec8fbb --- /dev/null +++ b/cpp/autosar/test/rules/M5-2-12/IdentifierWithArrayTypePassedAsFunctionArgumentDecayToAPointer.testref @@ -0,0 +1 @@ +cpp/common/test/rules/arraypassedasfunctionargumentdecaytoapointer/ArrayPassedAsFunctionArgumentDecayToAPointer.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M5-2-6/CastNotConvertPointerToFunction.expected b/cpp/autosar/test/rules/M5-2-6/CastNotConvertPointerToFunction.expected deleted file mode 100644 index 63c33f26d7..0000000000 --- a/cpp/autosar/test/rules/M5-2-6/CastNotConvertPointerToFunction.expected +++ /dev/null @@ -1,2 +0,0 @@ -| test.cpp:2:3:2:34 | reinterpret_cast<..(*)(..)>... | Cast converting a pointer to function. | -| test.cpp:3:3:3:30 | reinterpret_cast... | Cast converting a pointer to function. | diff --git a/cpp/autosar/test/rules/M5-2-6/CastNotConvertPointerToFunction.qlref b/cpp/autosar/test/rules/M5-2-6/CastNotConvertPointerToFunction.qlref deleted file mode 100644 index 7f4d4c1161..0000000000 --- a/cpp/autosar/test/rules/M5-2-6/CastNotConvertPointerToFunction.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M5-2-6/CastNotConvertPointerToFunction.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M5-2-6/CastNotConvertPointerToFunction.testref b/cpp/autosar/test/rules/M5-2-6/CastNotConvertPointerToFunction.testref new file mode 100644 index 0000000000..e7bde2ea08 --- /dev/null +++ b/cpp/autosar/test/rules/M5-2-6/CastNotConvertPointerToFunction.testref @@ -0,0 +1 @@ +cpp/common/test/rules/castsbetweenapointertofunctionandanyothertype/CastsBetweenAPointerToFunctionAndAnyOtherType.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M5-3-2/UnaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsigned.qlref b/cpp/autosar/test/rules/M5-3-2/UnaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsigned.qlref deleted file mode 100644 index 37d8a72ce5..0000000000 --- a/cpp/autosar/test/rules/M5-3-2/UnaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsigned.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M5-3-2/UnaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsigned.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M5-3-2/UnaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsigned.testref b/cpp/autosar/test/rules/M5-3-2/UnaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsigned.testref new file mode 100644 index 0000000000..bd12c39fbd --- /dev/null +++ b/cpp/autosar/test/rules/M5-3-2/UnaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsigned.testref @@ -0,0 +1 @@ +cpp/common/test/rules/builtinunaryoperatorappliedtounsignedexpression/BuiltInUnaryOperatorAppliedToUnsignedExpression.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M5-3-3/UnaryOperatorOverloaded.qlref b/cpp/autosar/test/rules/M5-3-3/UnaryOperatorOverloaded.qlref deleted file mode 100644 index 9e6cb1d0f8..0000000000 --- a/cpp/autosar/test/rules/M5-3-3/UnaryOperatorOverloaded.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M5-3-3/UnaryOperatorOverloaded.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M5-3-3/UnaryOperatorOverloaded.testref b/cpp/autosar/test/rules/M5-3-3/UnaryOperatorOverloaded.testref new file mode 100644 index 0000000000..1f2a126671 --- /dev/null +++ b/cpp/autosar/test/rules/M5-3-3/UnaryOperatorOverloaded.testref @@ -0,0 +1 @@ +cpp/common/test/rules/addressofoperatoroverloaded/AddressOfOperatorOverloaded.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M6-3-1/LoopCompoundCondition.qlref b/cpp/autosar/test/rules/M6-3-1/LoopCompoundCondition.qlref deleted file mode 100644 index 4ee6239a13..0000000000 --- a/cpp/autosar/test/rules/M6-3-1/LoopCompoundCondition.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M6-3-1/LoopCompoundCondition.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M6-3-1/LoopCompoundCondition.testref b/cpp/autosar/test/rules/M6-3-1/LoopCompoundCondition.testref new file mode 100644 index 0000000000..84dc7caf76 --- /dev/null +++ b/cpp/autosar/test/rules/M6-3-1/LoopCompoundCondition.testref @@ -0,0 +1 @@ +cpp/common/test/rules/loopcompoundcondition/LoopCompoundCondition.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M6-3-1/SwitchCompoundCondition.qlref b/cpp/autosar/test/rules/M6-3-1/SwitchCompoundCondition.qlref deleted file mode 100644 index eff312aa30..0000000000 --- a/cpp/autosar/test/rules/M6-3-1/SwitchCompoundCondition.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M6-3-1/SwitchCompoundCondition.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M6-3-1/SwitchCompoundCondition.testref b/cpp/autosar/test/rules/M6-3-1/SwitchCompoundCondition.testref new file mode 100644 index 0000000000..f02b02ba85 --- /dev/null +++ b/cpp/autosar/test/rules/M6-3-1/SwitchCompoundCondition.testref @@ -0,0 +1 @@ +cpp/common/test/rules/switchcompoundcondition/SwitchCompoundCondition.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M7-3-1/GlobalNamespaceMembershipViolation.qlref b/cpp/autosar/test/rules/M7-3-1/GlobalNamespaceMembershipViolation.qlref deleted file mode 100644 index f2ec336eec..0000000000 --- a/cpp/autosar/test/rules/M7-3-1/GlobalNamespaceMembershipViolation.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M7-3-1/GlobalNamespaceMembershipViolation.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M7-3-1/GlobalNamespaceMembershipViolation.testref b/cpp/autosar/test/rules/M7-3-1/GlobalNamespaceMembershipViolation.testref new file mode 100644 index 0000000000..8f71738005 --- /dev/null +++ b/cpp/autosar/test/rules/M7-3-1/GlobalNamespaceMembershipViolation.testref @@ -0,0 +1 @@ +cpp/common/test/rules/globalnamespacedeclarations/GlobalNamespaceDeclarations.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M7-3-2/IdentifierMainUsedForAFunctionOtherThanTheGlobalFunctionMain.qlref b/cpp/autosar/test/rules/M7-3-2/IdentifierMainUsedForAFunctionOtherThanTheGlobalFunctionMain.qlref deleted file mode 100644 index 36bc86bb79..0000000000 --- a/cpp/autosar/test/rules/M7-3-2/IdentifierMainUsedForAFunctionOtherThanTheGlobalFunctionMain.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M7-3-2/IdentifierMainUsedForAFunctionOtherThanTheGlobalFunctionMain.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M7-3-2/IdentifierMainUsedForAFunctionOtherThanTheGlobalFunctionMain.testref b/cpp/autosar/test/rules/M7-3-2/IdentifierMainUsedForAFunctionOtherThanTheGlobalFunctionMain.testref new file mode 100644 index 0000000000..e149f3a33b --- /dev/null +++ b/cpp/autosar/test/rules/M7-3-2/IdentifierMainUsedForAFunctionOtherThanTheGlobalFunctionMain.testref @@ -0,0 +1 @@ +cpp/common/test/rules/nonglobalfunctionmain/NonGlobalFunctionMain.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M7-5-1/FunctionReturnAutomaticVarCondition.qlref b/cpp/autosar/test/rules/M7-5-1/FunctionReturnAutomaticVarCondition.qlref deleted file mode 100644 index 4cb410e095..0000000000 --- a/cpp/autosar/test/rules/M7-5-1/FunctionReturnAutomaticVarCondition.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M7-5-1/FunctionReturnAutomaticVarCondition.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M7-5-1/FunctionReturnAutomaticVarCondition.testref b/cpp/autosar/test/rules/M7-5-1/FunctionReturnAutomaticVarCondition.testref new file mode 100644 index 0000000000..45dbffde00 --- /dev/null +++ b/cpp/autosar/test/rules/M7-5-1/FunctionReturnAutomaticVarCondition.testref @@ -0,0 +1 @@ +cpp/common/test/rules/returnreferenceorpointertoautomaticlocalvariable/ReturnReferenceOrPointerToAutomaticLocalVariable.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M8-0-1/MultipleGlobalOrMemberDeclarators.qlref b/cpp/autosar/test/rules/M8-0-1/MultipleGlobalOrMemberDeclarators.qlref deleted file mode 100644 index 2703512673..0000000000 --- a/cpp/autosar/test/rules/M8-0-1/MultipleGlobalOrMemberDeclarators.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M8-0-1/MultipleGlobalOrMemberDeclarators.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M8-0-1/MultipleGlobalOrMemberDeclarators.testref b/cpp/autosar/test/rules/M8-0-1/MultipleGlobalOrMemberDeclarators.testref new file mode 100644 index 0000000000..434cb47456 --- /dev/null +++ b/cpp/autosar/test/rules/M8-0-1/MultipleGlobalOrMemberDeclarators.testref @@ -0,0 +1 @@ +cpp/common/test/rules/multipleglobalormemberdeclarators/MultipleGlobalOrMemberDeclarators.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M8-0-1/MultipleLocalDeclarators.qlref b/cpp/autosar/test/rules/M8-0-1/MultipleLocalDeclarators.qlref deleted file mode 100644 index 2375201bf3..0000000000 --- a/cpp/autosar/test/rules/M8-0-1/MultipleLocalDeclarators.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M8-0-1/MultipleLocalDeclarators.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M8-0-1/MultipleLocalDeclarators.testref b/cpp/autosar/test/rules/M8-0-1/MultipleLocalDeclarators.testref new file mode 100644 index 0000000000..be7c9ac352 --- /dev/null +++ b/cpp/autosar/test/rules/M8-0-1/MultipleLocalDeclarators.testref @@ -0,0 +1 @@ +cpp/common/test/rules/multiplelocaldeclarators/MultipleLocalDeclarators.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M8-3-1/VirtualFunctionParametersUseTheSameDefaultArguments.expected b/cpp/autosar/test/rules/M8-3-1/VirtualFunctionParametersUseTheSameDefaultArguments.expected deleted file mode 100644 index b5cdd76a2b..0000000000 --- a/cpp/autosar/test/rules/M8-3-1/VirtualFunctionParametersUseTheSameDefaultArguments.expected +++ /dev/null @@ -1,2 +0,0 @@ -| test.cpp:16:8:16:8 | f | $@ does not have the same default parameters as $@ | test.cpp:16:8:16:8 | f | overriding function | test.cpp:4:16:4:16 | f | overridden function | -| test.cpp:21:8:21:8 | f | $@ does not have the same default parameters as $@ | test.cpp:21:8:21:8 | f | overriding function | test.cpp:4:16:4:16 | f | overridden function | diff --git a/cpp/autosar/test/rules/M8-3-1/VirtualFunctionParametersUseTheSameDefaultArguments.qlref b/cpp/autosar/test/rules/M8-3-1/VirtualFunctionParametersUseTheSameDefaultArguments.qlref deleted file mode 100644 index ae0c1df157..0000000000 --- a/cpp/autosar/test/rules/M8-3-1/VirtualFunctionParametersUseTheSameDefaultArguments.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M8-3-1/VirtualFunctionParametersUseTheSameDefaultArguments.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M8-3-1/VirtualFunctionParametersUseTheSameDefaultArguments.testref b/cpp/autosar/test/rules/M8-3-1/VirtualFunctionParametersUseTheSameDefaultArguments.testref new file mode 100644 index 0000000000..7e06403515 --- /dev/null +++ b/cpp/autosar/test/rules/M8-3-1/VirtualFunctionParametersUseTheSameDefaultArguments.testref @@ -0,0 +1 @@ +cpp/common/test/rules/overridingshallspecifydifferentdefaultarguments/OverridingShallSpecifyDifferentDefaultArguments.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M9-6-4/NamedBitFieldsWithSignedIntegerTypeShallHaveALengthOfMoreThanOneBit.expected b/cpp/autosar/test/rules/M9-6-4/NamedBitFieldsWithSignedIntegerTypeShallHaveALengthOfMoreThanOneBit.expected deleted file mode 100644 index 26b9aac563..0000000000 --- a/cpp/autosar/test/rules/M9-6-4/NamedBitFieldsWithSignedIntegerTypeShallHaveALengthOfMoreThanOneBit.expected +++ /dev/null @@ -1 +0,0 @@ -| test.cpp:2:14:2:14 | x | A named bit-field with signed integral type should have at least 2 bits of storage | diff --git a/cpp/autosar/test/rules/M9-6-4/NamedBitFieldsWithSignedIntegerTypeShallHaveALengthOfMoreThanOneBit.qlref b/cpp/autosar/test/rules/M9-6-4/NamedBitFieldsWithSignedIntegerTypeShallHaveALengthOfMoreThanOneBit.qlref deleted file mode 100644 index cdb9677f5f..0000000000 --- a/cpp/autosar/test/rules/M9-6-4/NamedBitFieldsWithSignedIntegerTypeShallHaveALengthOfMoreThanOneBit.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/M9-6-4/NamedBitFieldsWithSignedIntegerTypeShallHaveALengthOfMoreThanOneBit.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M9-6-4/NamedBitFieldsWithSignedIntegerTypeShallHaveALengthOfMoreThanOneBit.testref b/cpp/autosar/test/rules/M9-6-4/NamedBitFieldsWithSignedIntegerTypeShallHaveALengthOfMoreThanOneBit.testref new file mode 100644 index 0000000000..5dd7991a37 --- /dev/null +++ b/cpp/autosar/test/rules/M9-6-4/NamedBitFieldsWithSignedIntegerTypeShallHaveALengthOfMoreThanOneBit.testref @@ -0,0 +1 @@ +cpp/common/test/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/M9-6-4/test.cpp b/cpp/autosar/test/rules/M9-6-4/test.cpp deleted file mode 100644 index d3939b71ee..0000000000 --- a/cpp/autosar/test/rules/M9-6-4/test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -struct S { - signed int x : 1; // NON-COMPLIANT - signed int y : 5; // COMPLIANT - signed int z : 7; // COMPLIANT - signed int : 0; // COMPLIANT - signed int : 1; // COMPLIANT - signed int : 2; // COMPLIANT -}; \ No newline at end of file diff --git a/c/common/src/codingstandards/c/IrreplaceableFunctionLikeMacro.qll b/cpp/common/src/codingstandards/cpp/IrreplaceableFunctionLikeMacro.qll similarity index 100% rename from c/common/src/codingstandards/c/IrreplaceableFunctionLikeMacro.qll rename to cpp/common/src/codingstandards/cpp/IrreplaceableFunctionLikeMacro.qll diff --git a/cpp/common/src/codingstandards/cpp/Literals.qll b/cpp/common/src/codingstandards/cpp/Literals.qll index c6845b181d..66e15b28dc 100644 --- a/cpp/common/src/codingstandards/cpp/Literals.qll +++ b/cpp/common/src/codingstandards/cpp/Literals.qll @@ -5,6 +5,8 @@ import cpp import codingstandards.cpp.Cpp14Literal +class IntegerLiteral = Cpp14Literal::IntegerLiteral; + /** Gets `Literal.getValueText()` truncated to at most 20 characters. */ string getTruncatedLiteralText(Literal l) { exists(string text | text = l.getValueText() | diff --git a/cpp/autosar/src/rules/M14-6-1/NameInDependentBase.qll b/cpp/common/src/codingstandards/cpp/NameInDependentBase.qll similarity index 99% rename from cpp/autosar/src/rules/M14-6-1/NameInDependentBase.qll rename to cpp/common/src/codingstandards/cpp/NameInDependentBase.qll index b3d12c044b..e599f286ae 100644 --- a/cpp/autosar/src/rules/M14-6-1/NameInDependentBase.qll +++ b/cpp/common/src/codingstandards/cpp/NameInDependentBase.qll @@ -1,5 +1,4 @@ import cpp -import codingstandards.cpp.autosar /** * Gets a dependent base type of the given template class. diff --git a/cpp/autosar/src/rules/A18-5-4/OperatorDelete.qll b/cpp/common/src/codingstandards/cpp/OperatorDelete.qll similarity index 96% rename from cpp/autosar/src/rules/A18-5-4/OperatorDelete.qll rename to cpp/common/src/codingstandards/cpp/OperatorDelete.qll index ada7d109cd..c9ff315866 100644 --- a/cpp/autosar/src/rules/A18-5-4/OperatorDelete.qll +++ b/cpp/common/src/codingstandards/cpp/OperatorDelete.qll @@ -1,5 +1,4 @@ import cpp -import codingstandards.cpp.autosar class StdNoThrow extends Class { StdNoThrow() { hasQualifiedName("std", "nothrow_t") } diff --git a/cpp/common/src/codingstandards/cpp/exclusions/cpp/ImportMisra23.qll b/cpp/common/src/codingstandards/cpp/exclusions/cpp/ImportMisra23.qll index 86b4b9c5ae..d31affb27c 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/cpp/ImportMisra23.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/cpp/ImportMisra23.qll @@ -26,7 +26,68 @@ newtype ImportMisra23Query = TCallToSetlocaleInvalidatesOldPointersMisraQuery() or TCallToSetlocaleInvalidatesOldPointersWarnMisraQuery() or TObjectUsedWhileInPotentiallyMovedFromStateQuery() or - TReadsAndWritesOnStreamNotSeparatedByPositioningQuery() + TReadsAndWritesOnStreamNotSeparatedByPositioningQuery() or + TCommaOperatorShouldNotBeUsedQuery() or + TCopyAndMoveAssignmentsShallHandleSelfAssignmentQuery() or + TUseSingleLocalDeclaratorsQuery() or + TUseSingleGlobalOrMemberDeclaratorsQuery() or + TEnumerationNotDefinedWithAnExplicitUnderlyingTypeQuery() or + TAsmDeclarationShallNotBeUsedQuery() or + TNonUniqueEnumerationConstantQuery() or + TBitFieldShallHaveAnAppropriateTypeQuery() or + TSignedIntegerNamedBitFieldHaveALengthOfOneBitQuery() or + TVirtualAndNonVirtualClassInTheHierarchyQuery() or + TOverridingShallSpecifyDifferentDefaultArgumentsQuery() or + TPotentiallyVirtualPointerOnlyComparesToNullptrQuery() or + TObjectsDynamicTypeUsedFromConstructorOrDestructorQuery() or + TInitializeAllVirtualBaseClassesQuery() or + TInitializerListConstructorIsTheOnlyConstructorQuery() or + TAddressOfOperatorOverloadedQuery() or + TFunctionTemplatesExplicitlySpecializedQuery() or + TExceptionObjectHavePointerTypeQuery() or + TEmptyThrowOnlyWithinACatchHandlerQuery() or + TNoexceptFunctionShouldNotPropagateToTheCallerQuery() or + TFunctionLikeMacrosDefinedQuery() or + TMacroParameterFollowingHashQuery() or + TAMixedUseMacroArgumentSubjectToExpansionQuery() or + TCsignalFacilitiesUsedQuery() or + TCsignalTypesShallNotBeUsedQuery() or + TAtofAtoiAtolAndAtollUsedQuery() or + TMacroOffsetofShallNotBeUsedQuery() or + TGlobalSizedOperatorDeleteShallBeDefinedQuery() or + TGlobalUnsizedOperatorDeleteShallBeDefinedQuery() or + TVectorShouldNotBeSpecializedWithBoolQuery() or + TForwardingReferencesAndForwardNotUsedTogetherQuery() or + TCstdioFunctionsShallNotBeUsedQuery() or + TCstdioMacrosShallNotBeUsedQuery() or + TCstdioTypesShallNotBeUsedQuery() or + TBackslashCharacterMisuseQuery() or + TNonTerminatedEscapeSequencesQuery() or + TOctalConstantsUsedQuery() or + TUnsignedIntegerLiteralsNotAppropriatelySuffixedQuery() or + TLowercaseLStartsInLiteralSuffixQuery() or + TCharacterSequenceUsedWithinACStyleCommentQuery() or + TLineSplicingUsedInCommentsQuery() or + TGlobalNamespaceDeclarationsQuery() or + TNonGlobalFunctionMainQuery() or + TInheritedNonOverridableMemberFunctionQuery() or + TInheritedOverridableMemberFunctionQuery() or + TDefinitionShallBeConsideredForUnqualifiedLookupQuery() or + TNameShallBeReferredUsingAQualifiedIdOrThisQuery() or + TNameShallBeReferredUsingAQualifiedIdOrThisAuditQuery() or + TReturnReferenceOrPointerToAutomaticLocalVariableQuery() or + TNullptrNotTheOnlyFormOfTheNullPointerConstantQuery() or + TArrayPassedAsFunctionArgumentDecayToAPointerQuery() or + TResultOfAnAssignmentOperatorShouldNotBeUsedQuery() or + TFunctionsCallThemselvesEitherDirectlyOrIndirectlyQuery() or + TCastsBetweenAPointerToFunctionAndAnyOtherTypeQuery() or + TReinterpretCastShallNotBeUsedQuery() or + TUnsignedOperationWithConstantOperandsWrapsQuery() or + TBuiltInUnaryOperatorAppliedToUnsignedExpressionQuery() or + TSwitchBodyCompoundConditionQuery() or + TLoopBodyCompoundConditionQuery() or + TGotoStatementShouldNotBeUsedQuery() or + TGotoReferenceALabelInSurroundingBlockQuery() predicate isImportMisra23QueryMetadata(Query query, string queryId, string ruleId, string category) { query = @@ -235,6 +296,555 @@ predicate isImportMisra23QueryMetadata(Query query, string queryId, string ruleI "cpp/misra/reads-and-writes-on-stream-not-separated-by-positioning" and ruleId = "RULE-30-0-2" and category = "required" + or + query = + // `Query` instance for the `commaOperatorShouldNotBeUsed` query + ImportMisra23Package::commaOperatorShouldNotBeUsedQuery() and + queryId = + // `@id` for the `commaOperatorShouldNotBeUsed` query + "cpp/misra/comma-operator-should-not-be-used" and + ruleId = "RULE-8-19-1" and + category = "advisory" + or + query = + // `Query` instance for the `copyAndMoveAssignmentsShallHandleSelfAssignment` query + ImportMisra23Package::copyAndMoveAssignmentsShallHandleSelfAssignmentQuery() and + queryId = + // `@id` for the `copyAndMoveAssignmentsShallHandleSelfAssignment` query + "cpp/misra/copy-and-move-assignments-shall-handle-self-assignment" and + ruleId = "DIR-15-8-1" and + category = "required" + or + query = + // `Query` instance for the `useSingleLocalDeclarators` query + ImportMisra23Package::useSingleLocalDeclaratorsQuery() and + queryId = + // `@id` for the `useSingleLocalDeclarators` query + "cpp/misra/use-single-local-declarators" and + ruleId = "RULE-10-0-1" and + category = "advisory" + or + query = + // `Query` instance for the `useSingleGlobalOrMemberDeclarators` query + ImportMisra23Package::useSingleGlobalOrMemberDeclaratorsQuery() and + queryId = + // `@id` for the `useSingleGlobalOrMemberDeclarators` query + "cpp/misra/use-single-global-or-member-declarators" and + ruleId = "RULE-10-0-1" and + category = "advisory" + or + query = + // `Query` instance for the `enumerationNotDefinedWithAnExplicitUnderlyingType` query + ImportMisra23Package::enumerationNotDefinedWithAnExplicitUnderlyingTypeQuery() and + queryId = + // `@id` for the `enumerationNotDefinedWithAnExplicitUnderlyingType` query + "cpp/misra/enumeration-not-defined-with-an-explicit-underlying-type" and + ruleId = "RULE-10-2-1" and + category = "required" + or + query = + // `Query` instance for the `asmDeclarationShallNotBeUsed` query + ImportMisra23Package::asmDeclarationShallNotBeUsedQuery() and + queryId = + // `@id` for the `asmDeclarationShallNotBeUsed` query + "cpp/misra/asm-declaration-shall-not-be-used" and + ruleId = "RULE-10-4-1" and + category = "required" + or + query = + // `Query` instance for the `nonUniqueEnumerationConstant` query + ImportMisra23Package::nonUniqueEnumerationConstantQuery() and + queryId = + // `@id` for the `nonUniqueEnumerationConstant` query + "cpp/misra/non-unique-enumeration-constant" and + ruleId = "RULE-11-6-3" and + category = "required" + or + query = + // `Query` instance for the `bitFieldShallHaveAnAppropriateType` query + ImportMisra23Package::bitFieldShallHaveAnAppropriateTypeQuery() and + queryId = + // `@id` for the `bitFieldShallHaveAnAppropriateType` query + "cpp/misra/bit-field-shall-have-an-appropriate-type" and + ruleId = "RULE-12-2-2" and + category = "required" + or + query = + // `Query` instance for the `signedIntegerNamedBitFieldHaveALengthOfOneBit` query + ImportMisra23Package::signedIntegerNamedBitFieldHaveALengthOfOneBitQuery() and + queryId = + // `@id` for the `signedIntegerNamedBitFieldHaveALengthOfOneBit` query + "cpp/misra/signed-integer-named-bit-field-have-a-length-of-one-bit" and + ruleId = "RULE-12-2-3" and + category = "required" + or + query = + // `Query` instance for the `virtualAndNonVirtualClassInTheHierarchy` query + ImportMisra23Package::virtualAndNonVirtualClassInTheHierarchyQuery() and + queryId = + // `@id` for the `virtualAndNonVirtualClassInTheHierarchy` query + "cpp/misra/virtual-and-non-virtual-class-in-the-hierarchy" and + ruleId = "RULE-13-1-2" and + category = "required" + or + query = + // `Query` instance for the `overridingShallSpecifyDifferentDefaultArguments` query + ImportMisra23Package::overridingShallSpecifyDifferentDefaultArgumentsQuery() and + queryId = + // `@id` for the `overridingShallSpecifyDifferentDefaultArguments` query + "cpp/misra/overriding-shall-specify-different-default-arguments" and + ruleId = "RULE-13-3-2" and + category = "required" + or + query = + // `Query` instance for the `potentiallyVirtualPointerOnlyComparesToNullptr` query + ImportMisra23Package::potentiallyVirtualPointerOnlyComparesToNullptrQuery() and + queryId = + // `@id` for the `potentiallyVirtualPointerOnlyComparesToNullptr` query + "cpp/misra/potentially-virtual-pointer-only-compares-to-nullptr" and + ruleId = "RULE-13-3-4" and + category = "required" + or + query = + // `Query` instance for the `objectsDynamicTypeUsedFromConstructorOrDestructor` query + ImportMisra23Package::objectsDynamicTypeUsedFromConstructorOrDestructorQuery() and + queryId = + // `@id` for the `objectsDynamicTypeUsedFromConstructorOrDestructor` query + "cpp/misra/objects-dynamic-type-used-from-constructor-or-destructor" and + ruleId = "RULE-15-1-1" and + category = "required" + or + query = + // `Query` instance for the `initializeAllVirtualBaseClasses` query + ImportMisra23Package::initializeAllVirtualBaseClassesQuery() and + queryId = + // `@id` for the `initializeAllVirtualBaseClasses` query + "cpp/misra/initialize-all-virtual-base-classes" and + ruleId = "RULE-15-1-2" and + category = "advisory" + or + query = + // `Query` instance for the `initializerListConstructorIsTheOnlyConstructor` query + ImportMisra23Package::initializerListConstructorIsTheOnlyConstructorQuery() and + queryId = + // `@id` for the `initializerListConstructorIsTheOnlyConstructor` query + "cpp/misra/initializer-list-constructor-is-the-only-constructor" and + ruleId = "RULE-15-1-5" and + category = "required" + or + query = + // `Query` instance for the `addressOfOperatorOverloaded` query + ImportMisra23Package::addressOfOperatorOverloadedQuery() and + queryId = + // `@id` for the `addressOfOperatorOverloaded` query + "cpp/misra/address-of-operator-overloaded" and + ruleId = "RULE-16-5-2" and + category = "required" + or + query = + // `Query` instance for the `functionTemplatesExplicitlySpecialized` query + ImportMisra23Package::functionTemplatesExplicitlySpecializedQuery() and + queryId = + // `@id` for the `functionTemplatesExplicitlySpecialized` query + "cpp/misra/function-templates-explicitly-specialized" and + ruleId = "RULE-17-8-1" and + category = "required" + or + query = + // `Query` instance for the `exceptionObjectHavePointerType` query + ImportMisra23Package::exceptionObjectHavePointerTypeQuery() and + queryId = + // `@id` for the `exceptionObjectHavePointerType` query + "cpp/misra/exception-object-have-pointer-type" and + ruleId = "RULE-18-1-1" and + category = "required" + or + query = + // `Query` instance for the `emptyThrowOnlyWithinACatchHandler` query + ImportMisra23Package::emptyThrowOnlyWithinACatchHandlerQuery() and + queryId = + // `@id` for the `emptyThrowOnlyWithinACatchHandler` query + "cpp/misra/empty-throw-only-within-a-catch-handler" and + ruleId = "RULE-18-1-2" and + category = "required" + or + query = + // `Query` instance for the `noexceptFunctionShouldNotPropagateToTheCaller` query + ImportMisra23Package::noexceptFunctionShouldNotPropagateToTheCallerQuery() and + queryId = + // `@id` for the `noexceptFunctionShouldNotPropagateToTheCaller` query + "cpp/misra/noexcept-function-should-not-propagate-to-the-caller" and + ruleId = "RULE-18-5-1" and + category = "advisory" + or + query = + // `Query` instance for the `functionLikeMacrosDefined` query + ImportMisra23Package::functionLikeMacrosDefinedQuery() and + queryId = + // `@id` for the `functionLikeMacrosDefined` query + "cpp/misra/function-like-macros-defined" and + ruleId = "RULE-19-0-2" and + category = "required" + or + query = + // `Query` instance for the `macroParameterFollowingHash` query + ImportMisra23Package::macroParameterFollowingHashQuery() and + queryId = + // `@id` for the `macroParameterFollowingHash` query + "cpp/misra/macro-parameter-following-hash" and + ruleId = "RULE-19-3-2" and + category = "required" + or + query = + // `Query` instance for the `aMixedUseMacroArgumentSubjectToExpansion` query + ImportMisra23Package::aMixedUseMacroArgumentSubjectToExpansionQuery() and + queryId = + // `@id` for the `aMixedUseMacroArgumentSubjectToExpansion` query + "cpp/misra/a-mixed-use-macro-argument-subject-to-expansion" and + ruleId = "RULE-19-3-3" and + category = "required" + or + query = + // `Query` instance for the `csignalFacilitiesUsed` query + ImportMisra23Package::csignalFacilitiesUsedQuery() and + queryId = + // `@id` for the `csignalFacilitiesUsed` query + "cpp/misra/csignal-facilities-used" and + ruleId = "RULE-21-10-3" and + category = "required" + or + query = + // `Query` instance for the `csignalTypesShallNotBeUsed` query + ImportMisra23Package::csignalTypesShallNotBeUsedQuery() and + queryId = + // `@id` for the `csignalTypesShallNotBeUsed` query + "cpp/misra/csignal-types-shall-not-be-used" and + ruleId = "RULE-21-10-3" and + category = "required" + or + query = + // `Query` instance for the `atofAtoiAtolAndAtollUsed` query + ImportMisra23Package::atofAtoiAtolAndAtollUsedQuery() and + queryId = + // `@id` for the `atofAtoiAtolAndAtollUsed` query + "cpp/misra/atof-atoi-atol-and-atoll-used" and + ruleId = "RULE-21-2-1" and + category = "required" + or + query = + // `Query` instance for the `macroOffsetofShallNotBeUsed` query + ImportMisra23Package::macroOffsetofShallNotBeUsedQuery() and + queryId = + // `@id` for the `macroOffsetofShallNotBeUsed` query + "cpp/misra/macro-offsetof-shall-not-be-used" and + ruleId = "RULE-21-2-4" and + category = "required" + or + query = + // `Query` instance for the `globalSizedOperatorDeleteShallBeDefined` query + ImportMisra23Package::globalSizedOperatorDeleteShallBeDefinedQuery() and + queryId = + // `@id` for the `globalSizedOperatorDeleteShallBeDefined` query + "cpp/misra/global-sized-operator-delete-shall-be-defined" and + ruleId = "RULE-21-6-4" and + category = "required" + or + query = + // `Query` instance for the `globalUnsizedOperatorDeleteShallBeDefined` query + ImportMisra23Package::globalUnsizedOperatorDeleteShallBeDefinedQuery() and + queryId = + // `@id` for the `globalUnsizedOperatorDeleteShallBeDefined` query + "cpp/misra/global-unsized-operator-delete-shall-be-defined" and + ruleId = "RULE-21-6-4" and + category = "required" + or + query = + // `Query` instance for the `vectorShouldNotBeSpecializedWithBool` query + ImportMisra23Package::vectorShouldNotBeSpecializedWithBoolQuery() and + queryId = + // `@id` for the `vectorShouldNotBeSpecializedWithBool` query + "cpp/misra/vector-should-not-be-specialized-with-bool" and + ruleId = "RULE-26-3-1" and + category = "advisory" + or + query = + // `Query` instance for the `forwardingReferencesAndForwardNotUsedTogether` query + ImportMisra23Package::forwardingReferencesAndForwardNotUsedTogetherQuery() and + queryId = + // `@id` for the `forwardingReferencesAndForwardNotUsedTogether` query + "cpp/misra/forwarding-references-and-forward-not-used-together" and + ruleId = "RULE-28-6-2" and + category = "required" + or + query = + // `Query` instance for the `cstdioFunctionsShallNotBeUsed` query + ImportMisra23Package::cstdioFunctionsShallNotBeUsedQuery() and + queryId = + // `@id` for the `cstdioFunctionsShallNotBeUsed` query + "cpp/misra/cstdio-functions-shall-not-be-used" and + ruleId = "RULE-30-0-1" and + category = "required" + or + query = + // `Query` instance for the `cstdioMacrosShallNotBeUsed` query + ImportMisra23Package::cstdioMacrosShallNotBeUsedQuery() and + queryId = + // `@id` for the `cstdioMacrosShallNotBeUsed` query + "cpp/misra/cstdio-macros-shall-not-be-used" and + ruleId = "RULE-30-0-1" and + category = "required" + or + query = + // `Query` instance for the `cstdioTypesShallNotBeUsed` query + ImportMisra23Package::cstdioTypesShallNotBeUsedQuery() and + queryId = + // `@id` for the `cstdioTypesShallNotBeUsed` query + "cpp/misra/cstdio-types-shall-not-be-used" and + ruleId = "RULE-30-0-1" and + category = "required" + or + query = + // `Query` instance for the `backslashCharacterMisuse` query + ImportMisra23Package::backslashCharacterMisuseQuery() and + queryId = + // `@id` for the `backslashCharacterMisuse` query + "cpp/misra/backslash-character-misuse" and + ruleId = "RULE-5-13-1" and + category = "required" + or + query = + // `Query` instance for the `nonTerminatedEscapeSequences` query + ImportMisra23Package::nonTerminatedEscapeSequencesQuery() and + queryId = + // `@id` for the `nonTerminatedEscapeSequences` query + "cpp/misra/non-terminated-escape-sequences" and + ruleId = "RULE-5-13-2" and + category = "required" + or + query = + // `Query` instance for the `octalConstantsUsed` query + ImportMisra23Package::octalConstantsUsedQuery() and + queryId = + // `@id` for the `octalConstantsUsed` query + "cpp/misra/octal-constants-used" and + ruleId = "RULE-5-13-3" and + category = "required" + or + query = + // `Query` instance for the `unsignedIntegerLiteralsNotAppropriatelySuffixed` query + ImportMisra23Package::unsignedIntegerLiteralsNotAppropriatelySuffixedQuery() and + queryId = + // `@id` for the `unsignedIntegerLiteralsNotAppropriatelySuffixed` query + "cpp/misra/unsigned-integer-literals-not-appropriately-suffixed" and + ruleId = "RULE-5-13-4" and + category = "required" + or + query = + // `Query` instance for the `lowercaseLStartsInLiteralSuffix` query + ImportMisra23Package::lowercaseLStartsInLiteralSuffixQuery() and + queryId = + // `@id` for the `lowercaseLStartsInLiteralSuffix` query + "cpp/misra/lowercase-l-starts-in-literal-suffix" and + ruleId = "RULE-5-13-5" and + category = "required" + or + query = + // `Query` instance for the `characterSequenceUsedWithinACStyleComment` query + ImportMisra23Package::characterSequenceUsedWithinACStyleCommentQuery() and + queryId = + // `@id` for the `characterSequenceUsedWithinACStyleComment` query + "cpp/misra/character-sequence-used-within-ac-style-comment" and + ruleId = "RULE-5-7-1" and + category = "required" + or + query = + // `Query` instance for the `lineSplicingUsedInComments` query + ImportMisra23Package::lineSplicingUsedInCommentsQuery() and + queryId = + // `@id` for the `lineSplicingUsedInComments` query + "cpp/misra/line-splicing-used-in-comments" and + ruleId = "RULE-5-7-3" and + category = "required" + or + query = + // `Query` instance for the `globalNamespaceDeclarations` query + ImportMisra23Package::globalNamespaceDeclarationsQuery() and + queryId = + // `@id` for the `globalNamespaceDeclarations` query + "cpp/misra/global-namespace-declarations" and + ruleId = "RULE-6-0-3" and + category = "advisory" + or + query = + // `Query` instance for the `nonGlobalFunctionMain` query + ImportMisra23Package::nonGlobalFunctionMainQuery() and + queryId = + // `@id` for the `nonGlobalFunctionMain` query + "cpp/misra/non-global-function-main" and + ruleId = "RULE-6-0-4" and + category = "required" + or + query = + // `Query` instance for the `inheritedNonOverridableMemberFunction` query + ImportMisra23Package::inheritedNonOverridableMemberFunctionQuery() and + queryId = + // `@id` for the `inheritedNonOverridableMemberFunction` query + "cpp/misra/inherited-non-overridable-member-function" and + ruleId = "RULE-6-4-2" and + category = "required" + or + query = + // `Query` instance for the `inheritedOverridableMemberFunction` query + ImportMisra23Package::inheritedOverridableMemberFunctionQuery() and + queryId = + // `@id` for the `inheritedOverridableMemberFunction` query + "cpp/misra/inherited-overridable-member-function" and + ruleId = "RULE-6-4-2" and + category = "required" + or + query = + // `Query` instance for the `definitionShallBeConsideredForUnqualifiedLookup` query + ImportMisra23Package::definitionShallBeConsideredForUnqualifiedLookupQuery() and + queryId = + // `@id` for the `definitionShallBeConsideredForUnqualifiedLookup` query + "cpp/misra/definition-shall-be-considered-for-unqualified-lookup" and + ruleId = "RULE-6-4-2" and + category = "required" + or + query = + // `Query` instance for the `nameShallBeReferredUsingAQualifiedIdOrThis` query + ImportMisra23Package::nameShallBeReferredUsingAQualifiedIdOrThisQuery() and + queryId = + // `@id` for the `nameShallBeReferredUsingAQualifiedIdOrThis` query + "cpp/misra/name-shall-be-referred-using-a-qualified-id-or-this" and + ruleId = "RULE-6-4-3" and + category = "required" + or + query = + // `Query` instance for the `nameShallBeReferredUsingAQualifiedIdOrThisAudit` query + ImportMisra23Package::nameShallBeReferredUsingAQualifiedIdOrThisAuditQuery() and + queryId = + // `@id` for the `nameShallBeReferredUsingAQualifiedIdOrThisAudit` query + "cpp/misra/name-shall-be-referred-using-a-qualified-id-or-this-audit" and + ruleId = "RULE-6-4-3" and + category = "required" + or + query = + // `Query` instance for the `returnReferenceOrPointerToAutomaticLocalVariable` query + ImportMisra23Package::returnReferenceOrPointerToAutomaticLocalVariableQuery() and + queryId = + // `@id` for the `returnReferenceOrPointerToAutomaticLocalVariable` query + "cpp/misra/return-reference-or-pointer-to-automatic-local-variable" and + ruleId = "RULE-6-8-2" and + category = "mandatory" + or + query = + // `Query` instance for the `nullptrNotTheOnlyFormOfTheNullPointerConstant` query + ImportMisra23Package::nullptrNotTheOnlyFormOfTheNullPointerConstantQuery() and + queryId = + // `@id` for the `nullptrNotTheOnlyFormOfTheNullPointerConstant` query + "cpp/misra/nullptr-not-the-only-form-of-the-null-pointer-constant" and + ruleId = "RULE-7-11-1" and + category = "required" + or + query = + // `Query` instance for the `arrayPassedAsFunctionArgumentDecayToAPointer` query + ImportMisra23Package::arrayPassedAsFunctionArgumentDecayToAPointerQuery() and + queryId = + // `@id` for the `arrayPassedAsFunctionArgumentDecayToAPointer` query + "cpp/misra/array-passed-as-function-argument-decay-to-a-pointer" and + ruleId = "RULE-7-11-2" and + category = "required" + or + query = + // `Query` instance for the `resultOfAnAssignmentOperatorShouldNotBeUsed` query + ImportMisra23Package::resultOfAnAssignmentOperatorShouldNotBeUsedQuery() and + queryId = + // `@id` for the `resultOfAnAssignmentOperatorShouldNotBeUsed` query + "cpp/misra/result-of-an-assignment-operator-should-not-be-used" and + ruleId = "RULE-8-18-2" and + category = "advisory" + or + query = + // `Query` instance for the `functionsCallThemselvesEitherDirectlyOrIndirectly` query + ImportMisra23Package::functionsCallThemselvesEitherDirectlyOrIndirectlyQuery() and + queryId = + // `@id` for the `functionsCallThemselvesEitherDirectlyOrIndirectly` query + "cpp/misra/functions-call-themselves-either-directly-or-indirectly" and + ruleId = "RULE-8-2-10" and + category = "required" + or + query = + // `Query` instance for the `castsBetweenAPointerToFunctionAndAnyOtherType` query + ImportMisra23Package::castsBetweenAPointerToFunctionAndAnyOtherTypeQuery() and + queryId = + // `@id` for the `castsBetweenAPointerToFunctionAndAnyOtherType` query + "cpp/misra/casts-between-a-pointer-to-function-and-any-other-type" and + ruleId = "RULE-8-2-4" and + category = "required" + or + query = + // `Query` instance for the `reinterpretCastShallNotBeUsed` query + ImportMisra23Package::reinterpretCastShallNotBeUsedQuery() and + queryId = + // `@id` for the `reinterpretCastShallNotBeUsed` query + "cpp/misra/reinterpret-cast-shall-not-be-used" and + ruleId = "RULE-8-2-5" and + category = "required" + or + query = + // `Query` instance for the `unsignedOperationWithConstantOperandsWraps` query + ImportMisra23Package::unsignedOperationWithConstantOperandsWrapsQuery() and + queryId = + // `@id` for the `unsignedOperationWithConstantOperandsWraps` query + "cpp/misra/unsigned-operation-with-constant-operands-wraps" and + ruleId = "RULE-8-20-1" and + category = "advisory" + or + query = + // `Query` instance for the `builtInUnaryOperatorAppliedToUnsignedExpression` query + ImportMisra23Package::builtInUnaryOperatorAppliedToUnsignedExpressionQuery() and + queryId = + // `@id` for the `builtInUnaryOperatorAppliedToUnsignedExpression` query + "cpp/misra/built-in-unary-operator-applied-to-unsigned-expression" and + ruleId = "RULE-8-3-1" and + category = "advisory" + or + query = + // `Query` instance for the `switchBodyCompoundCondition` query + ImportMisra23Package::switchBodyCompoundConditionQuery() and + queryId = + // `@id` for the `switchBodyCompoundCondition` query + "cpp/misra/switch-body-compound-condition" and + ruleId = "RULE-9-3-1" and + category = "required" + or + query = + // `Query` instance for the `loopBodyCompoundCondition` query + ImportMisra23Package::loopBodyCompoundConditionQuery() and + queryId = + // `@id` for the `loopBodyCompoundCondition` query + "cpp/misra/loop-body-compound-condition" and + ruleId = "RULE-9-3-1" and + category = "required" + or + query = + // `Query` instance for the `gotoStatementShouldNotBeUsed` query + ImportMisra23Package::gotoStatementShouldNotBeUsedQuery() and + queryId = + // `@id` for the `gotoStatementShouldNotBeUsed` query + "cpp/misra/goto-statement-should-not-be-used" and + ruleId = "RULE-9-6-1" and + category = "advisory" + or + query = + // `Query` instance for the `gotoReferenceALabelInSurroundingBlock` query + ImportMisra23Package::gotoReferenceALabelInSurroundingBlockQuery() and + queryId = + // `@id` for the `gotoReferenceALabelInSurroundingBlock` query + "cpp/misra/goto-reference-a-label-in-surrounding-block" and + ruleId = "RULE-9-6-2" and + category = "required" } module ImportMisra23Package { @@ -398,4 +1008,431 @@ module ImportMisra23Package { // `Query` type for `readsAndWritesOnStreamNotSeparatedByPositioning` query TQueryCPP(TImportMisra23PackageQuery(TReadsAndWritesOnStreamNotSeparatedByPositioningQuery())) } + + Query commaOperatorShouldNotBeUsedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `commaOperatorShouldNotBeUsed` query + TQueryCPP(TImportMisra23PackageQuery(TCommaOperatorShouldNotBeUsedQuery())) + } + + Query copyAndMoveAssignmentsShallHandleSelfAssignmentQuery() { + //autogenerate `Query` type + result = + // `Query` type for `copyAndMoveAssignmentsShallHandleSelfAssignment` query + TQueryCPP(TImportMisra23PackageQuery(TCopyAndMoveAssignmentsShallHandleSelfAssignmentQuery())) + } + + Query useSingleLocalDeclaratorsQuery() { + //autogenerate `Query` type + result = + // `Query` type for `useSingleLocalDeclarators` query + TQueryCPP(TImportMisra23PackageQuery(TUseSingleLocalDeclaratorsQuery())) + } + + Query useSingleGlobalOrMemberDeclaratorsQuery() { + //autogenerate `Query` type + result = + // `Query` type for `useSingleGlobalOrMemberDeclarators` query + TQueryCPP(TImportMisra23PackageQuery(TUseSingleGlobalOrMemberDeclaratorsQuery())) + } + + Query enumerationNotDefinedWithAnExplicitUnderlyingTypeQuery() { + //autogenerate `Query` type + result = + // `Query` type for `enumerationNotDefinedWithAnExplicitUnderlyingType` query + TQueryCPP(TImportMisra23PackageQuery(TEnumerationNotDefinedWithAnExplicitUnderlyingTypeQuery())) + } + + Query asmDeclarationShallNotBeUsedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `asmDeclarationShallNotBeUsed` query + TQueryCPP(TImportMisra23PackageQuery(TAsmDeclarationShallNotBeUsedQuery())) + } + + Query nonUniqueEnumerationConstantQuery() { + //autogenerate `Query` type + result = + // `Query` type for `nonUniqueEnumerationConstant` query + TQueryCPP(TImportMisra23PackageQuery(TNonUniqueEnumerationConstantQuery())) + } + + Query bitFieldShallHaveAnAppropriateTypeQuery() { + //autogenerate `Query` type + result = + // `Query` type for `bitFieldShallHaveAnAppropriateType` query + TQueryCPP(TImportMisra23PackageQuery(TBitFieldShallHaveAnAppropriateTypeQuery())) + } + + Query signedIntegerNamedBitFieldHaveALengthOfOneBitQuery() { + //autogenerate `Query` type + result = + // `Query` type for `signedIntegerNamedBitFieldHaveALengthOfOneBit` query + TQueryCPP(TImportMisra23PackageQuery(TSignedIntegerNamedBitFieldHaveALengthOfOneBitQuery())) + } + + Query virtualAndNonVirtualClassInTheHierarchyQuery() { + //autogenerate `Query` type + result = + // `Query` type for `virtualAndNonVirtualClassInTheHierarchy` query + TQueryCPP(TImportMisra23PackageQuery(TVirtualAndNonVirtualClassInTheHierarchyQuery())) + } + + Query overridingShallSpecifyDifferentDefaultArgumentsQuery() { + //autogenerate `Query` type + result = + // `Query` type for `overridingShallSpecifyDifferentDefaultArguments` query + TQueryCPP(TImportMisra23PackageQuery(TOverridingShallSpecifyDifferentDefaultArgumentsQuery())) + } + + Query potentiallyVirtualPointerOnlyComparesToNullptrQuery() { + //autogenerate `Query` type + result = + // `Query` type for `potentiallyVirtualPointerOnlyComparesToNullptr` query + TQueryCPP(TImportMisra23PackageQuery(TPotentiallyVirtualPointerOnlyComparesToNullptrQuery())) + } + + Query objectsDynamicTypeUsedFromConstructorOrDestructorQuery() { + //autogenerate `Query` type + result = + // `Query` type for `objectsDynamicTypeUsedFromConstructorOrDestructor` query + TQueryCPP(TImportMisra23PackageQuery(TObjectsDynamicTypeUsedFromConstructorOrDestructorQuery())) + } + + Query initializeAllVirtualBaseClassesQuery() { + //autogenerate `Query` type + result = + // `Query` type for `initializeAllVirtualBaseClasses` query + TQueryCPP(TImportMisra23PackageQuery(TInitializeAllVirtualBaseClassesQuery())) + } + + Query initializerListConstructorIsTheOnlyConstructorQuery() { + //autogenerate `Query` type + result = + // `Query` type for `initializerListConstructorIsTheOnlyConstructor` query + TQueryCPP(TImportMisra23PackageQuery(TInitializerListConstructorIsTheOnlyConstructorQuery())) + } + + Query addressOfOperatorOverloadedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `addressOfOperatorOverloaded` query + TQueryCPP(TImportMisra23PackageQuery(TAddressOfOperatorOverloadedQuery())) + } + + Query functionTemplatesExplicitlySpecializedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `functionTemplatesExplicitlySpecialized` query + TQueryCPP(TImportMisra23PackageQuery(TFunctionTemplatesExplicitlySpecializedQuery())) + } + + Query exceptionObjectHavePointerTypeQuery() { + //autogenerate `Query` type + result = + // `Query` type for `exceptionObjectHavePointerType` query + TQueryCPP(TImportMisra23PackageQuery(TExceptionObjectHavePointerTypeQuery())) + } + + Query emptyThrowOnlyWithinACatchHandlerQuery() { + //autogenerate `Query` type + result = + // `Query` type for `emptyThrowOnlyWithinACatchHandler` query + TQueryCPP(TImportMisra23PackageQuery(TEmptyThrowOnlyWithinACatchHandlerQuery())) + } + + Query noexceptFunctionShouldNotPropagateToTheCallerQuery() { + //autogenerate `Query` type + result = + // `Query` type for `noexceptFunctionShouldNotPropagateToTheCaller` query + TQueryCPP(TImportMisra23PackageQuery(TNoexceptFunctionShouldNotPropagateToTheCallerQuery())) + } + + Query functionLikeMacrosDefinedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `functionLikeMacrosDefined` query + TQueryCPP(TImportMisra23PackageQuery(TFunctionLikeMacrosDefinedQuery())) + } + + Query macroParameterFollowingHashQuery() { + //autogenerate `Query` type + result = + // `Query` type for `macroParameterFollowingHash` query + TQueryCPP(TImportMisra23PackageQuery(TMacroParameterFollowingHashQuery())) + } + + Query aMixedUseMacroArgumentSubjectToExpansionQuery() { + //autogenerate `Query` type + result = + // `Query` type for `aMixedUseMacroArgumentSubjectToExpansion` query + TQueryCPP(TImportMisra23PackageQuery(TAMixedUseMacroArgumentSubjectToExpansionQuery())) + } + + Query csignalFacilitiesUsedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `csignalFacilitiesUsed` query + TQueryCPP(TImportMisra23PackageQuery(TCsignalFacilitiesUsedQuery())) + } + + Query csignalTypesShallNotBeUsedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `csignalTypesShallNotBeUsed` query + TQueryCPP(TImportMisra23PackageQuery(TCsignalTypesShallNotBeUsedQuery())) + } + + Query atofAtoiAtolAndAtollUsedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `atofAtoiAtolAndAtollUsed` query + TQueryCPP(TImportMisra23PackageQuery(TAtofAtoiAtolAndAtollUsedQuery())) + } + + Query macroOffsetofShallNotBeUsedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `macroOffsetofShallNotBeUsed` query + TQueryCPP(TImportMisra23PackageQuery(TMacroOffsetofShallNotBeUsedQuery())) + } + + Query globalSizedOperatorDeleteShallBeDefinedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `globalSizedOperatorDeleteShallBeDefined` query + TQueryCPP(TImportMisra23PackageQuery(TGlobalSizedOperatorDeleteShallBeDefinedQuery())) + } + + Query globalUnsizedOperatorDeleteShallBeDefinedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `globalUnsizedOperatorDeleteShallBeDefined` query + TQueryCPP(TImportMisra23PackageQuery(TGlobalUnsizedOperatorDeleteShallBeDefinedQuery())) + } + + Query vectorShouldNotBeSpecializedWithBoolQuery() { + //autogenerate `Query` type + result = + // `Query` type for `vectorShouldNotBeSpecializedWithBool` query + TQueryCPP(TImportMisra23PackageQuery(TVectorShouldNotBeSpecializedWithBoolQuery())) + } + + Query forwardingReferencesAndForwardNotUsedTogetherQuery() { + //autogenerate `Query` type + result = + // `Query` type for `forwardingReferencesAndForwardNotUsedTogether` query + TQueryCPP(TImportMisra23PackageQuery(TForwardingReferencesAndForwardNotUsedTogetherQuery())) + } + + Query cstdioFunctionsShallNotBeUsedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `cstdioFunctionsShallNotBeUsed` query + TQueryCPP(TImportMisra23PackageQuery(TCstdioFunctionsShallNotBeUsedQuery())) + } + + Query cstdioMacrosShallNotBeUsedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `cstdioMacrosShallNotBeUsed` query + TQueryCPP(TImportMisra23PackageQuery(TCstdioMacrosShallNotBeUsedQuery())) + } + + Query cstdioTypesShallNotBeUsedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `cstdioTypesShallNotBeUsed` query + TQueryCPP(TImportMisra23PackageQuery(TCstdioTypesShallNotBeUsedQuery())) + } + + Query backslashCharacterMisuseQuery() { + //autogenerate `Query` type + result = + // `Query` type for `backslashCharacterMisuse` query + TQueryCPP(TImportMisra23PackageQuery(TBackslashCharacterMisuseQuery())) + } + + Query nonTerminatedEscapeSequencesQuery() { + //autogenerate `Query` type + result = + // `Query` type for `nonTerminatedEscapeSequences` query + TQueryCPP(TImportMisra23PackageQuery(TNonTerminatedEscapeSequencesQuery())) + } + + Query octalConstantsUsedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `octalConstantsUsed` query + TQueryCPP(TImportMisra23PackageQuery(TOctalConstantsUsedQuery())) + } + + Query unsignedIntegerLiteralsNotAppropriatelySuffixedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `unsignedIntegerLiteralsNotAppropriatelySuffixed` query + TQueryCPP(TImportMisra23PackageQuery(TUnsignedIntegerLiteralsNotAppropriatelySuffixedQuery())) + } + + Query lowercaseLStartsInLiteralSuffixQuery() { + //autogenerate `Query` type + result = + // `Query` type for `lowercaseLStartsInLiteralSuffix` query + TQueryCPP(TImportMisra23PackageQuery(TLowercaseLStartsInLiteralSuffixQuery())) + } + + Query characterSequenceUsedWithinACStyleCommentQuery() { + //autogenerate `Query` type + result = + // `Query` type for `characterSequenceUsedWithinACStyleComment` query + TQueryCPP(TImportMisra23PackageQuery(TCharacterSequenceUsedWithinACStyleCommentQuery())) + } + + Query lineSplicingUsedInCommentsQuery() { + //autogenerate `Query` type + result = + // `Query` type for `lineSplicingUsedInComments` query + TQueryCPP(TImportMisra23PackageQuery(TLineSplicingUsedInCommentsQuery())) + } + + Query globalNamespaceDeclarationsQuery() { + //autogenerate `Query` type + result = + // `Query` type for `globalNamespaceDeclarations` query + TQueryCPP(TImportMisra23PackageQuery(TGlobalNamespaceDeclarationsQuery())) + } + + Query nonGlobalFunctionMainQuery() { + //autogenerate `Query` type + result = + // `Query` type for `nonGlobalFunctionMain` query + TQueryCPP(TImportMisra23PackageQuery(TNonGlobalFunctionMainQuery())) + } + + Query inheritedNonOverridableMemberFunctionQuery() { + //autogenerate `Query` type + result = + // `Query` type for `inheritedNonOverridableMemberFunction` query + TQueryCPP(TImportMisra23PackageQuery(TInheritedNonOverridableMemberFunctionQuery())) + } + + Query inheritedOverridableMemberFunctionQuery() { + //autogenerate `Query` type + result = + // `Query` type for `inheritedOverridableMemberFunction` query + TQueryCPP(TImportMisra23PackageQuery(TInheritedOverridableMemberFunctionQuery())) + } + + Query definitionShallBeConsideredForUnqualifiedLookupQuery() { + //autogenerate `Query` type + result = + // `Query` type for `definitionShallBeConsideredForUnqualifiedLookup` query + TQueryCPP(TImportMisra23PackageQuery(TDefinitionShallBeConsideredForUnqualifiedLookupQuery())) + } + + Query nameShallBeReferredUsingAQualifiedIdOrThisQuery() { + //autogenerate `Query` type + result = + // `Query` type for `nameShallBeReferredUsingAQualifiedIdOrThis` query + TQueryCPP(TImportMisra23PackageQuery(TNameShallBeReferredUsingAQualifiedIdOrThisQuery())) + } + + Query nameShallBeReferredUsingAQualifiedIdOrThisAuditQuery() { + //autogenerate `Query` type + result = + // `Query` type for `nameShallBeReferredUsingAQualifiedIdOrThisAudit` query + TQueryCPP(TImportMisra23PackageQuery(TNameShallBeReferredUsingAQualifiedIdOrThisAuditQuery())) + } + + Query returnReferenceOrPointerToAutomaticLocalVariableQuery() { + //autogenerate `Query` type + result = + // `Query` type for `returnReferenceOrPointerToAutomaticLocalVariable` query + TQueryCPP(TImportMisra23PackageQuery(TReturnReferenceOrPointerToAutomaticLocalVariableQuery())) + } + + Query nullptrNotTheOnlyFormOfTheNullPointerConstantQuery() { + //autogenerate `Query` type + result = + // `Query` type for `nullptrNotTheOnlyFormOfTheNullPointerConstant` query + TQueryCPP(TImportMisra23PackageQuery(TNullptrNotTheOnlyFormOfTheNullPointerConstantQuery())) + } + + Query arrayPassedAsFunctionArgumentDecayToAPointerQuery() { + //autogenerate `Query` type + result = + // `Query` type for `arrayPassedAsFunctionArgumentDecayToAPointer` query + TQueryCPP(TImportMisra23PackageQuery(TArrayPassedAsFunctionArgumentDecayToAPointerQuery())) + } + + Query resultOfAnAssignmentOperatorShouldNotBeUsedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `resultOfAnAssignmentOperatorShouldNotBeUsed` query + TQueryCPP(TImportMisra23PackageQuery(TResultOfAnAssignmentOperatorShouldNotBeUsedQuery())) + } + + Query functionsCallThemselvesEitherDirectlyOrIndirectlyQuery() { + //autogenerate `Query` type + result = + // `Query` type for `functionsCallThemselvesEitherDirectlyOrIndirectly` query + TQueryCPP(TImportMisra23PackageQuery(TFunctionsCallThemselvesEitherDirectlyOrIndirectlyQuery())) + } + + Query castsBetweenAPointerToFunctionAndAnyOtherTypeQuery() { + //autogenerate `Query` type + result = + // `Query` type for `castsBetweenAPointerToFunctionAndAnyOtherType` query + TQueryCPP(TImportMisra23PackageQuery(TCastsBetweenAPointerToFunctionAndAnyOtherTypeQuery())) + } + + Query reinterpretCastShallNotBeUsedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `reinterpretCastShallNotBeUsed` query + TQueryCPP(TImportMisra23PackageQuery(TReinterpretCastShallNotBeUsedQuery())) + } + + Query unsignedOperationWithConstantOperandsWrapsQuery() { + //autogenerate `Query` type + result = + // `Query` type for `unsignedOperationWithConstantOperandsWraps` query + TQueryCPP(TImportMisra23PackageQuery(TUnsignedOperationWithConstantOperandsWrapsQuery())) + } + + Query builtInUnaryOperatorAppliedToUnsignedExpressionQuery() { + //autogenerate `Query` type + result = + // `Query` type for `builtInUnaryOperatorAppliedToUnsignedExpression` query + TQueryCPP(TImportMisra23PackageQuery(TBuiltInUnaryOperatorAppliedToUnsignedExpressionQuery())) + } + + Query switchBodyCompoundConditionQuery() { + //autogenerate `Query` type + result = + // `Query` type for `switchBodyCompoundCondition` query + TQueryCPP(TImportMisra23PackageQuery(TSwitchBodyCompoundConditionQuery())) + } + + Query loopBodyCompoundConditionQuery() { + //autogenerate `Query` type + result = + // `Query` type for `loopBodyCompoundCondition` query + TQueryCPP(TImportMisra23PackageQuery(TLoopBodyCompoundConditionQuery())) + } + + Query gotoStatementShouldNotBeUsedQuery() { + //autogenerate `Query` type + result = + // `Query` type for `gotoStatementShouldNotBeUsed` query + TQueryCPP(TImportMisra23PackageQuery(TGotoStatementShouldNotBeUsedQuery())) + } + + Query gotoReferenceALabelInSurroundingBlockQuery() { + //autogenerate `Query` type + result = + // `Query` type for `gotoReferenceALabelInSurroundingBlock` query + TQueryCPP(TImportMisra23PackageQuery(TGotoReferenceALabelInSurroundingBlockQuery())) + } } diff --git a/cpp/common/src/codingstandards/cpp/rules/addressofoperatoroverloaded/AddressOfOperatorOverloaded.qll b/cpp/common/src/codingstandards/cpp/rules/addressofoperatoroverloaded/AddressOfOperatorOverloaded.qll new file mode 100644 index 0000000000..603a75bd01 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/addressofoperatoroverloaded/AddressOfOperatorOverloaded.qll @@ -0,0 +1,17 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * The address-of operator shall not be overloaded. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.Operator + +abstract class AddressOfOperatorOverloadedSharedQuery extends Query { } + +Query getQuery() { result instanceof AddressOfOperatorOverloadedSharedQuery } + +query predicate problems(UnaryAddressOfOperator e, string message) { + not isExcluded(e, getQuery()) and message = "The unary & operator overloaded." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.qll b/cpp/common/src/codingstandards/cpp/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.qll new file mode 100644 index 0000000000..da17706f54 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.qll @@ -0,0 +1,34 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * The argument to a mixed-use macro parameter shall not be subject to further + * expansion. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.Macro + +abstract class AMixedUseMacroArgumentSubjectToExpansionSharedQuery extends Query { } + +Query getQuery() { result instanceof AMixedUseMacroArgumentSubjectToExpansionSharedQuery } + +query predicate problems(FunctionLikeMacro m, string message) { + exists(MacroInvocation mi, int i, string expanded, string param | + not isExcluded(m, getQuery()) and + mi = m.getAnInvocation() and + param = m.getParameter(i) and + ( + exists(TokenPastingOperator op | op.getMacro() = m and op.getOperand() = param) + or + exists(StringizingOperator op | op.getMacro() = m and op.getOperand() = param) + ) and + // An expansion that is equal to "" means the expansion is not used and is optimized away by EDG. This happens when the expanded argument is an operand to `#` or `##`. + // This check ensure there is an expansion that is used. + expanded = mi.getExpandedArgument(i) and + not expanded = "" and + not mi.getUnexpandedArgument(i) = mi.getExpandedArgument(i) and + message = + "Macro " + m.getName() + " contains use of parameter " + param + " used in multiple contexts." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/arraypassedasfunctionargumentdecaytoapointer/ArrayPassedAsFunctionArgumentDecayToAPointer.qll b/cpp/common/src/codingstandards/cpp/rules/arraypassedasfunctionargumentdecaytoapointer/ArrayPassedAsFunctionArgumentDecayToAPointer.qll new file mode 100644 index 0000000000..b7ec4917bd --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/arraypassedasfunctionargumentdecaytoapointer/ArrayPassedAsFunctionArgumentDecayToAPointer.qll @@ -0,0 +1,46 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * An array passed as a function argument shall not decay to a pointer. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class ArrayPassedAsFunctionArgumentDecayToAPointerSharedQuery extends Query { } + +Query getQuery() { result instanceof ArrayPassedAsFunctionArgumentDecayToAPointerSharedQuery } + +predicate arrayToPointerDecay(Access ae, Parameter p) { + ( + p.getType() instanceof PointerType and + // exclude parameters of void* because then it assumed the caller can pass in dimensions through other means. + // examples are uses in `memset` or `memcpy` + not p.getType() instanceof VoidPointerType + or + p.getType() instanceof ArrayType + ) and + ae.getType() instanceof ArrayType and + // exclude char[] arrays because we assume that we can determine its dimension by looking for a NULL byte. + not ae.getType().(ArrayType).getBaseType() instanceof CharType +} + +query predicate problems( + Element e, string message, Variable array, string array_string, Parameter decayedArray, + string decayedArray_string, Function f, string f_string +) { + exists(FunctionCall fc, VariableAccess arrayAccess, int i | + not isExcluded(e, getQuery()) and + arrayAccess = array.getAnAccess() and + f = fc.getTarget() and + arrayAccess = fc.getArgument(i) and + decayedArray = f.getParameter(i) and + arrayToPointerDecay(arrayAccess, decayedArray) and + not arrayAccess.isAffectedByMacro() and + e = fc.getArgument(i) and + array_string = array.getName() and + decayedArray_string = decayedArray.getName() and + f_string = f.getName() and + message = "The array $@ decays to the pointer $@ when passed as an argument to the function $@." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/asmdeclarationused/AsmDeclarationUsed.qll b/cpp/common/src/codingstandards/cpp/rules/asmdeclarationused/AsmDeclarationUsed.qll new file mode 100644 index 0000000000..c6748683da --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/asmdeclarationused/AsmDeclarationUsed.qll @@ -0,0 +1,16 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * The asm declaration shall not be used. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class AsmDeclarationUsedSharedQuery extends Query { } + +Query getQuery() { result instanceof AsmDeclarationUsedSharedQuery } + +query predicate problems(AsmStmt e, string message) { + not isExcluded(e, getQuery()) and message = "Use of asm declaration" +} diff --git a/cpp/common/src/codingstandards/cpp/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.qll b/cpp/common/src/codingstandards/cpp/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.qll new file mode 100644 index 0000000000..295e346913 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.qll @@ -0,0 +1,24 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * The library functions atof, atoi, atol and atoll from shall not be used. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +private string atoi() { result = ["atof", "atoi", "atol", "atoll"] } + +abstract class AtofAtoiAtolAndAtollUsedSharedQuery extends Query { } + +Query getQuery() { result instanceof AtofAtoiAtolAndAtollUsedSharedQuery } + +query predicate problems(FunctionCall fc, string message) { + exists(Function f | + not isExcluded(fc, getQuery()) and + f = fc.getTarget() and + f.getName() = atoi() and + f.getFile().getBaseName() = "stdlib.h" and + message = "Call to banned function " + f.getName() + "." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/backslashcharactermisuse/BackslashCharacterMisuse.qll b/cpp/common/src/codingstandards/cpp/rules/backslashcharactermisuse/BackslashCharacterMisuse.qll new file mode 100644 index 0000000000..34cb93fb39 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/backslashcharactermisuse/BackslashCharacterMisuse.qll @@ -0,0 +1,23 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * In character literals and non-raw string literals, \ shall only be used to form a + * defined escape sequence or universal character name. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class BackslashCharacterMisuseSharedQuery extends Query { } + +Query getQuery() { result instanceof BackslashCharacterMisuseSharedQuery } + +query predicate problems(StringLiteral l, string message) { + exists(string es | + not isExcluded(l, getQuery()) and + es = l.getANonStandardEscapeSequence(_, _) and + // Exclude universal-character-names, which begin with \u or \U + not es.toLowerCase().matches("\\u") and + message = "This literal contains the non-standard escape sequence " + es + "." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.qll b/cpp/common/src/codingstandards/cpp/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.qll new file mode 100644 index 0000000000..27048b2d25 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.qll @@ -0,0 +1,41 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * A bit-field shall have an appropriate type. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.Compiler + +abstract class BitFieldShallHaveAnAppropriateTypeSharedQuery extends Query { } + +Query getQuery() { result instanceof BitFieldShallHaveAnAppropriateTypeSharedQuery } + +Type getSupportedBitFieldType(Compiler compiler) { + compiler instanceof UnsupportedCompiler and + ( + result instanceof IntType and + ( + result.(IntegralType).isExplicitlySigned() or + result.(IntegralType).isExplicitlyUnsigned() + ) + or + result instanceof BoolType + ) + or + (compiler instanceof Gcc or compiler instanceof Clang) and + ( + result instanceof IntegralOrEnumType + or + result instanceof BoolType + ) +} + +query predicate problems(BitField bitField, string message) { + not isExcluded(bitField, getQuery()) and + /* A violation would neither be an appropriate primitive type nor an appropriate typedef. */ + not getSupportedBitFieldType(getCompiler(bitField.getFile())) = + bitField.getType().resolveTypedefs() and + message = "Bit-field '" + bitField + "' is declared on type '" + bitField.getType() + "'." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/builtinunaryoperatorappliedtounsignedexpression/BuiltInUnaryOperatorAppliedToUnsignedExpression.qll b/cpp/common/src/codingstandards/cpp/rules/builtinunaryoperatorappliedtounsignedexpression/BuiltInUnaryOperatorAppliedToUnsignedExpression.qll new file mode 100644 index 0000000000..0e516a43ec --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/builtinunaryoperatorappliedtounsignedexpression/BuiltInUnaryOperatorAppliedToUnsignedExpression.qll @@ -0,0 +1,25 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * The built-in unary - operator should not be applied to an expression of unsigned + * type. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class BuiltInUnaryOperatorAppliedToUnsignedExpressionSharedQuery extends Query { } + +Query getQuery() { result instanceof BuiltInUnaryOperatorAppliedToUnsignedExpressionSharedQuery } + +query predicate problems(Element e, string message) { + exists(UnaryMinusExpr ex, IntegralType t | + t = ex.getOperand().getExplicitlyConverted().getType().getUnderlyingType() and + t.isUnsigned() and + not ex.isAffectedByMacro() and + e = ex.getOperand() and + not isExcluded(e, getQuery()) and + message = + "The unary minus operator shall not be applied to an expression whose underlying type is unsigned." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/castsbetweenapointertofunctionandanyothertype/CastsBetweenAPointerToFunctionAndAnyOtherType.qll b/cpp/common/src/codingstandards/cpp/rules/castsbetweenapointertofunctionandanyothertype/CastsBetweenAPointerToFunctionAndAnyOtherType.qll new file mode 100644 index 0000000000..48fa1f0c86 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/castsbetweenapointertofunctionandanyothertype/CastsBetweenAPointerToFunctionAndAnyOtherType.qll @@ -0,0 +1,20 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Casts shall not be performed between a pointer to function and any other type. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class CastsBetweenAPointerToFunctionAndAnyOtherTypeSharedQuery extends Query { } + +Query getQuery() { result instanceof CastsBetweenAPointerToFunctionAndAnyOtherTypeSharedQuery } + +query predicate problems(Cast c, string message) { + not isExcluded(c, getQuery()) and + not c.isImplicit() and + not c.isAffectedByMacro() and + c.getExpr().getType() instanceof FunctionPointerType and + message = "Cast converting a pointer to function." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/charactersequenceusedwithinacstylecomment/CharacterSequenceUsedWithinACStyleComment.qll b/cpp/common/src/codingstandards/cpp/rules/charactersequenceusedwithinacstylecomment/CharacterSequenceUsedWithinACStyleComment.qll new file mode 100644 index 0000000000..676b2d3030 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/charactersequenceusedwithinacstylecomment/CharacterSequenceUsedWithinACStyleComment.qll @@ -0,0 +1,18 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * The presence of a nested /* comment can indicate accidentally commented out code. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class CharacterSequenceUsedWithinACStyleCommentSharedQuery extends Query { } + +Query getQuery() { result instanceof CharacterSequenceUsedWithinACStyleCommentSharedQuery } + +query predicate problems(CStyleComment c, string message) { + not isExcluded(c, getQuery()) and + exists(c.getContents().regexpFind("./\\*", _, _)) and + message = "C-style /* comment includes nested /*." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/commaoperatorused/CommaOperatorUsed.qll b/cpp/common/src/codingstandards/cpp/rules/commaoperatorused/CommaOperatorUsed.qll index a6a80969b8..6985f7fc1e 100644 --- a/cpp/common/src/codingstandards/cpp/rules/commaoperatorused/CommaOperatorUsed.qll +++ b/cpp/common/src/codingstandards/cpp/rules/commaoperatorused/CommaOperatorUsed.qll @@ -1,5 +1,6 @@ /** - * Provides a library which includes a `problems` predicate for reporting.... + * Provides a library with a `problems` predicate for the following issue: + * The comma operator shall not be used. */ import cpp diff --git a/cpp/common/src/codingstandards/cpp/rules/constlikereturnvalue/ConstLikeReturnValue.qll b/cpp/common/src/codingstandards/cpp/rules/constlikereturnvalue/ConstLikeReturnValue.qll index f4636b6b13..2f672a1181 100644 --- a/cpp/common/src/codingstandards/cpp/rules/constlikereturnvalue/ConstLikeReturnValue.qll +++ b/cpp/common/src/codingstandards/cpp/rules/constlikereturnvalue/ConstLikeReturnValue.qll @@ -1,5 +1,8 @@ /** - * Provides a library which includes a `problems` predicate for reporting.... + * Provides a library with a `problems` predicate for the following issue: + * The pointers returned by the Standard Library functions localeconv, getenv, + * setlocale or, strerror shall only be used as if they have pointer to + * const-qualified type. */ import cpp diff --git a/cpp/common/src/codingstandards/cpp/rules/copyandmoveassignmentsshallhandleselfassignment/CopyAndMoveAssignmentsShallHandleSelfAssignment.qll b/cpp/common/src/codingstandards/cpp/rules/copyandmoveassignmentsshallhandleselfassignment/CopyAndMoveAssignmentsShallHandleSelfAssignment.qll new file mode 100644 index 0000000000..ae87176517 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/copyandmoveassignmentsshallhandleselfassignment/CopyAndMoveAssignmentsShallHandleSelfAssignment.qll @@ -0,0 +1,53 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * User-provided copy assignment operators and move assignment operators shall handle + * self-assignment. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.Operator + +abstract class CopyAndMoveAssignmentsShallHandleSelfAssignmentSharedQuery extends Query { } + +Query getQuery() { result instanceof CopyAndMoveAssignmentsShallHandleSelfAssignmentSharedQuery } + +predicate isUserCopyOrUserMove(Operator o) { + o instanceof UserCopyOperator or + o instanceof UserMoveOperator +} + +predicate callsStdSwap(Function f) { + exists(FunctionCall fc | + fc.getTarget().hasGlobalOrStdName("swap") and + fc.getEnclosingFunction() = f + ) +} + +predicate callsNoExceptSwap(Operator o) { + exists(Function f, FunctionCall fc | + callsStdSwap(f) and + fc.getEnclosingFunction() = o and + fc.getTarget() = f + ) +} + +predicate checksForSelfAssignment(Operator o) { + exists(IfStmt i, ComparisonOperation c | + i.getEnclosingFunction() = o and + i.getCondition() = c and + ( + c.getLeftOperand().toString() = "this" or + c.getRightOperand().toString() = "this" + ) + ) +} + +query predicate problems(Operator o, string message) { + not isExcluded(o, getQuery()) and + isUserCopyOrUserMove(o) and + not callsNoExceptSwap(o) and + not checksForSelfAssignment(o) and + message = "User defined copy or user defined move does not handle self-assignment correctly." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/csignalfunctionsused/CsignalFunctionsUsed.qll b/cpp/common/src/codingstandards/cpp/rules/csignalfunctionsused/CsignalFunctionsUsed.qll new file mode 100644 index 0000000000..15c71018f9 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/csignalfunctionsused/CsignalFunctionsUsed.qll @@ -0,0 +1,21 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Signal handling contains implementation-defined and undefined behaviour. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class CsignalFunctionsUsedSharedQuery extends Query { } + +Query getQuery() { result instanceof CsignalFunctionsUsedSharedQuery } + +query predicate problems(FunctionCall fc, string message) { + exists(Function f | + not isExcluded(fc, getQuery()) and + f = fc.getTarget() and + f.hasGlobalOrStdName(["signal", "raise"]) and + message = "Use of function '" + f.getQualifiedName() + "'." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/csignaltypesused/CsignalTypesUsed.qll b/cpp/common/src/codingstandards/cpp/rules/csignaltypesused/CsignalTypesUsed.qll new file mode 100644 index 0000000000..21de1066f6 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/csignaltypesused/CsignalTypesUsed.qll @@ -0,0 +1,21 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Signal handling contains implementation-defined and undefined behaviour. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class CsignalTypesUsedSharedQuery extends Query { } + +Query getQuery() { result instanceof CsignalTypesUsedSharedQuery } + +query predicate problems(TypeMention tm, string message) { + exists(UserType ut | + not isExcluded(tm, getQuery()) and + ut = tm.getMentionedType() and + ut.hasGlobalOrStdName("sig_atomic_t") and + message = "Use of type '" + ut.getQualifiedName() + "'." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/cstdiofunctionsused/CstdioFunctionsUsed.qll b/cpp/common/src/codingstandards/cpp/rules/cstdiofunctionsused/CstdioFunctionsUsed.qll new file mode 100644 index 0000000000..284997dc19 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/cstdiofunctionsused/CstdioFunctionsUsed.qll @@ -0,0 +1,38 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Streams and file I/O have a large number of unspecified, undefined, and + * implementation-defined behaviours associated with them. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class CstdioFunctionsUsedSharedQuery extends Query { } + +Query getQuery() { result instanceof CstdioFunctionsUsedSharedQuery } + +query predicate problems(FunctionCall fc, string message) { + exists(Function f | + not isExcluded(fc, getQuery()) and + f = fc.getTarget() and + f.hasGlobalOrStdName([ + "remove", "rename", "tmpfile", "tmpnam", + // File access + "fclose", "fflush", "fopen", "freopen", "setbuf", "setvbuf", + // Formatted input/output + "fprintf", "fscanf", "printf", "scanf", "snprintf", "sprintf", "sscanf", "vfprintf", + "vfscanf", "vprintf", "vscanf", "vsnprintf", "vsprintf", "vsscanf", + // Character input/output + "fgetc", "fgets", "fputc", "fputs", "getc", "getchar", "gets", "putc", "putchar", "puts", + "ungetc", + // Direct input/output + "fread", "fwrite", + // File positioning + "fgetpos", "fseek", "fsetpos", "ftell", "rewind", + // Error handling + "clearerr", "feof", "ferror", "perror" + ]) and + message = "Use of function '" + f.getQualifiedName() + "'." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/cstdiomacrosused/CstdioMacrosUsed.qll b/cpp/common/src/codingstandards/cpp/rules/cstdiomacrosused/CstdioMacrosUsed.qll new file mode 100644 index 0000000000..d610b6a166 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/cstdiomacrosused/CstdioMacrosUsed.qll @@ -0,0 +1,22 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Streams and file I/O have a large number of unspecified, undefined, and + * implementation-defined behaviours associated with them. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class CstdioMacrosUsedSharedQuery extends Query { } + +Query getQuery() { result instanceof CstdioMacrosUsedSharedQuery } + +query predicate problems(MacroInvocation mi, string message) { + not isExcluded(mi, getQuery()) and + mi.getMacroName() in [ + "BUFSIZ", "EOF", "FILENAME_MAX", "FOPEN_MAX", "L_tmpnam", "TMP_MAX", "_IOFBF", "IOLBF", + "_IONBF", "SEEK_CUR", "SEEK_END", "SEEK_SET" + ] and + message = "Use of macro '" + mi.getMacroName() + "'." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/cstdiotypesused/CstdioTypesUsed.qll b/cpp/common/src/codingstandards/cpp/rules/cstdiotypesused/CstdioTypesUsed.qll new file mode 100644 index 0000000000..d517d78c8b --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/cstdiotypesused/CstdioTypesUsed.qll @@ -0,0 +1,27 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Streams and file I/O have a large number of unspecified, undefined, and + * implementation-defined behaviours associated with them. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class CstdioTypesUsedSharedQuery extends Query { } + +Query getQuery() { result instanceof CstdioTypesUsedSharedQuery } + +query predicate problems(TypeMention tm, string message) { + exists(UserType ut | + not isExcluded(tm, getQuery()) and + ut = tm.getMentionedType() and + ut.hasGlobalOrStdName(["FILE", "fpos_t"]) and + // Not in the standard library + exists(tm.getFile().getRelativePath()) and + // Not in our tests copy of the standard library + not tm.getFile().getRelativePath() = + ["includes/standard-library/stddef.h", "includes/standard-library/stdio.h"] and + message = "Use of type '" + ut.getQualifiedName() + "'." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/definitionnotconsideredforunqualifiedlookup/DefinitionNotConsideredForUnqualifiedLookup.qll b/cpp/common/src/codingstandards/cpp/rules/definitionnotconsideredforunqualifiedlookup/DefinitionNotConsideredForUnqualifiedLookup.qll new file mode 100644 index 0000000000..c2b857d600 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/definitionnotconsideredforunqualifiedlookup/DefinitionNotConsideredForUnqualifiedLookup.qll @@ -0,0 +1,70 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * A using declaration that makes a symbol available for unqualified lookup does not + * included definitions defined after the using declaration which can result in + * unexpected behavior. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class DefinitionNotConsideredForUnqualifiedLookupSharedQuery extends Query { } + +Query getQuery() { result instanceof DefinitionNotConsideredForUnqualifiedLookupSharedQuery } + +/** + * Holds if `functionDecl` is a possible intended target of the `usingDecl`. + */ +pragma[noinline] +predicate isPossibleIntendedTarget( + FunctionDeclarationEntry functionDecl, UsingDeclarationEntry usingDecl +) { + // Extracted to improve the join order. With this approach, we first compute a set of using + // declarations and a set of possible intended targets + functionDecl.getDeclaration().isTopLevel() and + functionDecl.getDeclaration().getQualifiedName() = usingDecl.getDeclaration().getQualifiedName() and + functionDecl.getDeclaration().getNamespace().getParentNamespace*() = usingDecl.getParentScope() +} + +/** + * Holds if `functionDecl` is a possible intended target of the `usingDecl`, and they exist at the + * given locations. + */ +pragma[noinline] +predicate isPossibleIntendedTargetLocation( + FunctionDeclarationEntry functionDecl, UsingDeclarationEntry usingDecl, File usingsFile, + File unavailableFile, int usingsStartLine, int unavailableStartLine +) { + // Extracted to improve the join order. With this approach, we take the set of possible intended + // targets computed in isPossibleIntendedTargets, and compute the files and start lines. + // This helps avoid the join order preferred by the optimiser if this is all written directly in + // the from-where-select, where it will eagerly join: + // + // usingDeclarationEntries -> enclosing files -> all other elements in those files + // + // which is expensive when there are a lot of files with using declarations + isPossibleIntendedTarget(functionDecl, usingDecl) and + usingsFile = usingDecl.getFile() and + unavailableFile = functionDecl.getFile() and + usingsStartLine = usingDecl.getLocation().getStartLine() and + unavailableStartLine = functionDecl.getLocation().getStartLine() +} + +query predicate problems( + FunctionDeclarationEntry unavailableDecl, string message, UsingDeclarationEntry usingDecl, + string usingDecl_string +) { + not isExcluded(unavailableDecl, getQuery()) and + exists(File usingsFile, File unavailableFile, int usingsStartLine, int unavailableStartLine | + isPossibleIntendedTargetLocation(unavailableDecl, usingDecl, usingsFile, unavailableFile, + usingsStartLine, unavailableStartLine) and + // An approximation of order where we want the using to preceed the new declaration. + usingsFile = unavailableFile and + usingsStartLine < unavailableStartLine + ) and + message = + "Definition for '" + unavailableDecl.getName() + + "' is not available for unqualified lookup because it is declared after $@" and + usingDecl_string = "using-declaration" +} diff --git a/cpp/common/src/codingstandards/cpp/rules/dereferenceofnullpointer/DereferenceOfNullPointer.qll b/cpp/common/src/codingstandards/cpp/rules/dereferenceofnullpointer/DereferenceOfNullPointer.qll index 5e3328cb63..950b14df3d 100644 --- a/cpp/common/src/codingstandards/cpp/rules/dereferenceofnullpointer/DereferenceOfNullPointer.qll +++ b/cpp/common/src/codingstandards/cpp/rules/dereferenceofnullpointer/DereferenceOfNullPointer.qll @@ -1,5 +1,6 @@ /** - * Provides a library which includes a `problems` predicate for reporting.... + * Provides a library with a `problems` predicate for the following issue: + * Dereferencing a NULL pointer leads to undefined behavior. */ import cpp diff --git a/cpp/common/src/codingstandards/cpp/rules/donotusesetjmporlongjmpshared/DoNotUseSetjmpOrLongjmpShared.qll b/cpp/common/src/codingstandards/cpp/rules/donotusesetjmporlongjmpshared/DoNotUseSetjmpOrLongjmpShared.qll index 6c39b62fec..1441b6ec97 100644 --- a/cpp/common/src/codingstandards/cpp/rules/donotusesetjmporlongjmpshared/DoNotUseSetjmpOrLongjmpShared.qll +++ b/cpp/common/src/codingstandards/cpp/rules/donotusesetjmporlongjmpshared/DoNotUseSetjmpOrLongjmpShared.qll @@ -1,5 +1,6 @@ /** - * Provides a library which includes a `problems` predicate for reporting.... + * Provides a library with a `problems` predicate for the following issue: + * The macro setjmp and function longjmp shall not be used. */ import cpp diff --git a/cpp/common/src/codingstandards/cpp/rules/emptythrowonlywithinacatchhandler/EmptyThrowOnlyWithinACatchHandler.qll b/cpp/common/src/codingstandards/cpp/rules/emptythrowonlywithinacatchhandler/EmptyThrowOnlyWithinACatchHandler.qll new file mode 100644 index 0000000000..3dba1a3aa3 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/emptythrowonlywithinacatchhandler/EmptyThrowOnlyWithinACatchHandler.qll @@ -0,0 +1,19 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Empty throws with no currently handled exception can cause abrupt program + * termination. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class EmptyThrowOnlyWithinACatchHandlerSharedQuery extends Query { } + +Query getQuery() { result instanceof EmptyThrowOnlyWithinACatchHandlerSharedQuery } + +query predicate problems(ReThrowExpr re, string message) { + not isExcluded(re, getQuery()) and + not re.getEnclosingElement+() instanceof CatchBlock and + message = "Rethrow outside catch block" +} diff --git a/cpp/common/src/codingstandards/cpp/rules/enumerationnotdefinedwithanexplicitunderlyingtype/EnumerationNotDefinedWithAnExplicitUnderlyingType.qll b/cpp/common/src/codingstandards/cpp/rules/enumerationnotdefinedwithanexplicitunderlyingtype/EnumerationNotDefinedWithAnExplicitUnderlyingType.qll new file mode 100644 index 0000000000..d014e7be86 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/enumerationnotdefinedwithanexplicitunderlyingtype/EnumerationNotDefinedWithAnExplicitUnderlyingType.qll @@ -0,0 +1,18 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Although scoped enum will implicitly define an underlying type of int, the underlying base type of enumeration should always be explicitly defined with a type that will be large enough to store all enumerators. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class EnumerationNotDefinedWithAnExplicitUnderlyingTypeSharedQuery extends Query { } + +Query getQuery() { result instanceof EnumerationNotDefinedWithAnExplicitUnderlyingTypeSharedQuery } + +query predicate problems(Enum e, string message) { + not isExcluded(e, getQuery()) and + not e.hasExplicitUnderlyingType() and + message = "Base type of enumeration is not explicitly specified." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/exceptionobjecthavepointertype/ExceptionObjectHavePointerType.qll b/cpp/common/src/codingstandards/cpp/rules/exceptionobjecthavepointertype/ExceptionObjectHavePointerType.qll new file mode 100644 index 0000000000..1989afbc8b --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/exceptionobjecthavepointertype/ExceptionObjectHavePointerType.qll @@ -0,0 +1,20 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Throwing an exception of pointer type can lead to use-after-free or memory leak + * issues. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class ExceptionObjectHavePointerTypeSharedQuery extends Query { } + +Query getQuery() { result instanceof ExceptionObjectHavePointerTypeSharedQuery } + +query predicate problems(Expr thrownExpr, string message) { + not isExcluded(thrownExpr, getQuery()) and + thrownExpr = any(ThrowExpr te).getExpr() and + thrownExpr.getType().getUnspecifiedType() instanceof PointerType and + message = "Exception object with pointer type " + thrownExpr.getType() + " is thrown here." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/forwardingreferencesandforwardnotusedtogether/ForwardingReferencesAndForwardNotUsedTogether.qll b/cpp/common/src/codingstandards/cpp/rules/forwardingreferencesandforwardnotusedtogether/ForwardingReferencesAndForwardNotUsedTogether.qll new file mode 100644 index 0000000000..960b4ba2b6 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/forwardingreferencesandforwardnotusedtogether/ForwardingReferencesAndForwardNotUsedTogether.qll @@ -0,0 +1,28 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Forwarding references and std::forward shall be used together. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.standardlibrary.Utility + +abstract class ForwardingReferencesAndForwardNotUsedTogetherSharedQuery extends Query { } + +Query getQuery() { result instanceof ForwardingReferencesAndForwardNotUsedTogetherSharedQuery } + +query predicate problems(FunctionCall c, string message, Parameter a, string a_string) { + not isExcluded(c, getQuery()) and + a_string = a.getName() and + a.getAnAccess() = c.getAnArgument() and + ( + c instanceof StdMoveCall and + a instanceof ForwardParameter and + message = "Function `std::forward` should be used for forwarding the forward reference $@." + or + c instanceof StdForwardCall and + a instanceof ConsumeParameter and + message = "Function `std::move` should be used for forwarding rvalue reference $@." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.qll b/cpp/common/src/codingstandards/cpp/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.qll new file mode 100644 index 0000000000..73e4181640 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.qll @@ -0,0 +1,31 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Function-like macros shall not be defined. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.IrreplaceableFunctionLikeMacro + +abstract class FunctionLikeMacrosDefinedSharedQuery extends Query { } + +Query getQuery() { result instanceof FunctionLikeMacrosDefinedSharedQuery } + +predicate partOfConstantExpr(MacroInvocation i) { + exists(Expr e | + e.isConstant() and + not i.getExpr() = e and + i.getExpr().getParent+() = e + ) +} + +query predicate problems(FunctionLikeMacro m, string message) { + not isExcluded(m, getQuery()) and + not m instanceof IrreplaceableFunctionLikeMacro and + //macros can have empty body + not m.getBody().length() = 0 and + //function call not allowed in a constant expression (where constant expr is parent) + forall(MacroInvocation i | i = m.getAnInvocation() | not partOfConstantExpr(i)) and + message = "Macro used instead of a function." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/functionscallthemselveseitherdirectlyorindirectly/FunctionsCallThemselvesEitherDirectlyOrIndirectly.qll b/cpp/common/src/codingstandards/cpp/rules/functionscallthemselveseitherdirectlyorindirectly/FunctionsCallThemselvesEitherDirectlyOrIndirectly.qll new file mode 100644 index 0000000000..87f27c134f --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/functionscallthemselveseitherdirectlyorindirectly/FunctionsCallThemselvesEitherDirectlyOrIndirectly.qll @@ -0,0 +1,35 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Using recursive functions can lead to stack overflows and limit scalability and + * portability of the program. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class FunctionsCallThemselvesEitherDirectlyOrIndirectlySharedQuery extends Query { } + +Query getQuery() { result instanceof FunctionsCallThemselvesEitherDirectlyOrIndirectlySharedQuery } + +class RecursiveCall extends FunctionCall { + RecursiveCall() { + this.getTarget().calls*(this.getEnclosingFunction()) and + not this.getTarget().hasSpecifier("is_constexpr") + } +} + +query predicate problems(FunctionCall fc, string message, Function f, string f_name) { + exists(RecursiveCall call | + not isExcluded(call, getQuery()) and + f = fc.getTarget() and + f_name = fc.getTarget().getName() and + fc.getTarget() = call.getTarget() and + if fc.getTarget() = fc.getEnclosingFunction() + then message = "This call directly invokes its containing function $@." + else + message = + "The function " + fc.getEnclosingFunction() + + " is indirectly recursive via this call to $@." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/functiontemplatesexplicitlyspecialized/FunctionTemplatesExplicitlySpecialized.qll b/cpp/common/src/codingstandards/cpp/rules/functiontemplatesexplicitlyspecialized/FunctionTemplatesExplicitlySpecialized.qll new file mode 100644 index 0000000000..d0f98d233e --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/functiontemplatesexplicitlyspecialized/FunctionTemplatesExplicitlySpecialized.qll @@ -0,0 +1,21 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Function templates shall not be explicitly specialized. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class FunctionTemplatesExplicitlySpecializedSharedQuery extends Query { } + +Query getQuery() { result instanceof FunctionTemplatesExplicitlySpecializedSharedQuery } + +query predicate problems( + FunctionTemplateSpecialization f, string message, TemplateFunction tf, string tf_string +) { + not isExcluded(f, getQuery()) and + tf = f.getPrimaryTemplate() and + tf_string = f.getPrimaryTemplate().getFile().getBaseName() and + message = "Specialization of function template from primary template located in $@." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/globalnamespacedeclarations/GlobalNamespaceDeclarations.qll b/cpp/common/src/codingstandards/cpp/rules/globalnamespacedeclarations/GlobalNamespaceDeclarations.qll new file mode 100644 index 0000000000..285ccd909a --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/globalnamespacedeclarations/GlobalNamespaceDeclarations.qll @@ -0,0 +1,23 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * The only declarations in the global namespace should be main, namespace declarations + * and extern "C" declarations. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class GlobalNamespaceDeclarationsSharedQuery extends Query { } + +Query getQuery() { result instanceof GlobalNamespaceDeclarationsSharedQuery } + +query predicate problems(DeclarationEntry e, string message) { + not isExcluded(e, getQuery()) and + e.getDeclaration().getNamespace() instanceof GlobalNamespace and + e.getDeclaration().isTopLevel() and + not exists(Function f | f = e.getDeclaration() | f.hasGlobalName("main") or f.hasCLinkage()) and + message = + "Declaration " + e.getName() + + " is in the global namespace and is not a main, a namespace, or an extern \"C\" declaration." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/globalsizedoperatordeletenotdefined/GlobalSizedOperatorDeleteNotDefined.qll b/cpp/common/src/codingstandards/cpp/rules/globalsizedoperatordeletenotdefined/GlobalSizedOperatorDeleteNotDefined.qll new file mode 100644 index 0000000000..c445c06253 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/globalsizedoperatordeletenotdefined/GlobalSizedOperatorDeleteNotDefined.qll @@ -0,0 +1,24 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * If a project has the unsized version of operator 'delete' globally defined, then the + * sized version shall be defined. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.OperatorDelete + +abstract class GlobalSizedOperatorDeleteNotDefinedSharedQuery extends Query { } + +Query getQuery() { result instanceof GlobalSizedOperatorDeleteNotDefinedSharedQuery } + +query predicate problems(OperatorDelete unsized_delete, string message) { + not isExcluded(unsized_delete, getQuery()) and + not unsized_delete.isSizeDelete() and + not exists(OperatorDelete od | unsized_delete.isNoThrowDelete() = od.isNoThrowDelete() | + od.isSizeDelete() + ) and + message = + "Unsized function '" + unsized_delete.getName() + "' defined globally without sized version." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/globalunsizedoperatordeletenotdefined/GlobalUnsizedOperatorDeleteNotDefined.qll b/cpp/common/src/codingstandards/cpp/rules/globalunsizedoperatordeletenotdefined/GlobalUnsizedOperatorDeleteNotDefined.qll new file mode 100644 index 0000000000..b99887ee03 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/globalunsizedoperatordeletenotdefined/GlobalUnsizedOperatorDeleteNotDefined.qll @@ -0,0 +1,24 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * If a project has the sized version of operator 'delete' globally defined, then the + * unsized version shall be defined. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.OperatorDelete + +abstract class GlobalUnsizedOperatorDeleteNotDefinedSharedQuery extends Query { } + +Query getQuery() { result instanceof GlobalUnsizedOperatorDeleteNotDefinedSharedQuery } + +query predicate problems(OperatorDelete sized_delete, string message) { + not isExcluded(sized_delete, getQuery()) and + sized_delete.isSizeDelete() and + not exists(OperatorDelete od | sized_delete.isNoThrowDelete() = od.isNoThrowDelete() | + not od.isSizeDelete() + ) and + message = + "Sized function '" + sized_delete.getName() + "' defined globally without unsized version." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.qll b/cpp/common/src/codingstandards/cpp/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.qll new file mode 100644 index 0000000000..f329fff12d --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.qll @@ -0,0 +1,60 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * A goto statement shall reference a label in a surrounding block. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class GotoReferenceALabelInSurroundingBlockSharedQuery extends Query { } + +Query getQuery() { result instanceof GotoReferenceALabelInSurroundingBlockSharedQuery } + +predicate isPartOfSwitch(Stmt goto) { + exists(SwitchStmt switch | switch.getStmt() = goto.getParent()) +} + +SwitchCase getSwitchCase(Stmt stmt) { + exists(int index, SwitchStmt switch | + getStmtInSwitch(switch, stmt, index) and getStmtInSwitch(switch, result, index - 1) + ) + or + exists(int index, SwitchStmt switch, Stmt other | + getStmtInSwitch(switch, stmt, index) and + getStmtInSwitch(switch, other, index - 1) and + not other instanceof SwitchCase and + result = getSwitchCase(other) + ) +} + +predicate getStmtInSwitch(SwitchStmt switch, Stmt s, int index) { + switch.getStmt().(BlockStmt).getStmt(index) = s +} + +int statementDepth(Stmt statement) { + statement.getParent() = statement.getEnclosingFunction().getBlock() and result = 1 + or + statementDepth(statement.getParent()) + 1 = result +} + +query predicate problems(GotoStmt goto, string message, Stmt target, string target_string) { + not isExcluded(goto, getQuery()) and + exists(int gotoDepth, int targetDepth | + goto.getTarget() = target and + gotoDepth = statementDepth(goto) and + targetDepth = statementDepth(target) and + targetDepth >= gotoDepth and + ( + targetDepth = gotoDepth + implies + ( + not isPartOfSwitch(goto) and not goto.getParent() = target.getParent() + or + isPartOfSwitch(goto) and not getSwitchCase(goto) = getSwitchCase(target) + ) + ) and + target_string = "label" and + message = "The goto statement and its $@ are not declared or enclosed in the same block." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.qll b/cpp/common/src/codingstandards/cpp/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.qll new file mode 100644 index 0000000000..6a13ea083c --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.qll @@ -0,0 +1,18 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * The goto statement shall not be used. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class GotoStatementShouldNotBeUsedSharedQuery extends Query { } + +Query getQuery() { result instanceof GotoStatementShouldNotBeUsedSharedQuery } + +query predicate problems(Stmt s, string message) { + not isExcluded(s, getQuery()) and + (s instanceof GotoStmt or s instanceof ComputedGotoStmt) and + message = "Use of goto." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/handleallexceptionsduringstartup/HandleAllExceptionsDuringStartup.qll b/cpp/common/src/codingstandards/cpp/rules/handleallexceptionsduringstartup/HandleAllExceptionsDuringStartup.qll index ccc0a23460..8d859f726d 100644 --- a/cpp/common/src/codingstandards/cpp/rules/handleallexceptionsduringstartup/HandleAllExceptionsDuringStartup.qll +++ b/cpp/common/src/codingstandards/cpp/rules/handleallexceptionsduringstartup/HandleAllExceptionsDuringStartup.qll @@ -1,5 +1,6 @@ /** - * Provides a library which includes a `problems` predicate for reporting.... + * Provides a library with a `problems` predicate for the following issue: + * Exceptions thrown before main begins executing cannot be caught. */ import cpp diff --git a/cpp/common/src/codingstandards/cpp/rules/hiddeninheritednonoverridablememberfunction/HiddenInheritedNonOverridableMemberFunction.qll b/cpp/common/src/codingstandards/cpp/rules/hiddeninheritednonoverridablememberfunction/HiddenInheritedNonOverridableMemberFunction.qll new file mode 100644 index 0000000000..1c371da20c --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/hiddeninheritednonoverridablememberfunction/HiddenInheritedNonOverridableMemberFunction.qll @@ -0,0 +1,58 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * A non-overriding member function definition that hides an inherited member function + * can result in unexpected behavior. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.Class + +abstract class HiddenInheritedNonOverridableMemberFunctionSharedQuery extends Query { } + +Query getQuery() { result instanceof HiddenInheritedNonOverridableMemberFunctionSharedQuery } + +/** + * Holds if the class has a non-virtual member function with the given name. + */ +pragma[noinline, nomagic] +predicate hasNonVirtualMemberFunction(Class clazz, MemberFunction mf, string name) { + mf.getDeclaringType() = clazz and + mf.getName() = name and + not mf.isVirtual() and + // Exclude private member functions, which cannot be inherited. + not mf.isPrivate() +} + +/** + * Holds if the member function is in a class with the given base class, and has the given name. + */ +pragma[noinline, nomagic] +predicate hasDeclarationBaseClass(MemberFunction mf, Class baseClass, string functionName) { + baseClass = mf.getDeclaringType().getABaseClass() and + functionName = mf.getName() +} + +query predicate problems( + MemberFunction overridingDecl, string message, MemberFunction hiddenDecl, string hiddenDecl_string +) { + exists(Class baseClass, string name | + not isExcluded(overridingDecl, getQuery()) and // Check if we are overriding a non-virtual inherited member function + hasNonVirtualMemberFunction(baseClass, hiddenDecl, name) and + hasDeclarationBaseClass(overridingDecl, baseClass, name) and + // Where the hidden member function isn't explicitly brought in scope through a using declaration. + not exists(UsingDeclarationEntry ude | + ude.getDeclaration() = hiddenDecl and + ude.getEnclosingElement() = overridingDecl.getDeclaringType() + ) and + // Exclude compiler generated member functions which include things like copy constructor that hide base class + // copy constructors. + not overridingDecl.isCompilerGenerated() and + // Exclude special member functions, which cannot be inherited. + not overridingDecl instanceof SpecialMemberFunction and + message = + "Declaration for member '" + name + "' hides non-overridable inherited member function $@" and + hiddenDecl_string = hiddenDecl.getName() + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/hiddeninheritedoverridablememberfunction/HiddenInheritedOverridableMemberFunction.qll b/cpp/common/src/codingstandards/cpp/rules/hiddeninheritedoverridablememberfunction/HiddenInheritedOverridableMemberFunction.qll new file mode 100644 index 0000000000..ef99e01973 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/hiddeninheritedoverridablememberfunction/HiddenInheritedOverridableMemberFunction.qll @@ -0,0 +1,56 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * An overriding member function definition thats hides an overload of the overridden + * inherited member function can result in unexpected behavior. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class HiddenInheritedOverridableMemberFunctionSharedQuery extends Query { } + +Query getQuery() { result instanceof HiddenInheritedOverridableMemberFunctionSharedQuery } + +query predicate problems( + FunctionDeclarationEntry overridingDecl, string message, FunctionDeclarationEntry hiddenDecl, + string hiddenDecl_string +) { + not isExcluded(overridingDecl, getQuery()) and + // Check if we are overriding a virtual inherited member function + hiddenDecl.getDeclaration().isVirtual() and + // Exclude private member functions, which cannot be inherited. + not hiddenDecl.getDeclaration().(MemberFunction).isPrivate() and + // The overriding declaration hides the hidden declaration if: + ( + // 1. the overriding declaration overrides a function in a base class that is an overload of the hidden declaration + // and the hidden declaration isn't overriden in the same class. + exists(FunctionDeclarationEntry overridenDecl | + overridingDecl.getDeclaration().(MemberFunction).overrides(overridenDecl.getDeclaration()) and + overridenDecl.getDeclaration().getAnOverload() = hiddenDecl.getDeclaration() and + not exists(MemberFunction overridingFunc | + hiddenDecl.getDeclaration().(MemberFunction).getAnOverridingFunction() = overridingFunc and + overridingFunc.getDeclaringType() = overridingDecl.getDeclaration().getDeclaringType() + ) + ) and + // and the hidden declaration isn't explicitly brought in scope through a using declaration. + not exists(UsingDeclarationEntry ude | + ude.getDeclaration() = hiddenDecl.getDeclaration() and + ude.getEnclosingElement() = overridingDecl.getDeclaration().getDeclaringType() + ) + or + // 2. if the overriding declaration doesn't override a base member function but has the same name + // as the hidden declaration + not overridingDecl.getDeclaration().(MemberFunction).overrides(_) and + overridingDecl.getName() = hiddenDecl.getName() and + overridingDecl.getDeclaration().getDeclaringType().getABaseClass() = + hiddenDecl.getDeclaration().getDeclaringType() + ) and + // Limit the results to the declarations and not the definitions, if any. + (overridingDecl.getDeclaration().hasDefinition() implies not overridingDecl.isDefinition()) and + (hiddenDecl.getDeclaration().hasDefinition() implies not hiddenDecl.isDefinition()) and + message = + "Declaration for member '" + overridingDecl.getName() + + "' hides overridable inherited member function $@" and + hiddenDecl_string = hiddenDecl.getName() +} diff --git a/cpp/common/src/codingstandards/cpp/rules/identifierhidden/IdentifierHidden.qll b/cpp/common/src/codingstandards/cpp/rules/identifierhidden/IdentifierHidden.qll index dc71ba843e..9534c2f78a 100644 --- a/cpp/common/src/codingstandards/cpp/rules/identifierhidden/IdentifierHidden.qll +++ b/cpp/common/src/codingstandards/cpp/rules/identifierhidden/IdentifierHidden.qll @@ -1,5 +1,8 @@ /** - * Provides a library which includes a `problems` predicate for reporting.... + * Provides a library with a `problems` predicate for the following issue: + * Use of an identifier declared in an inner scope with an identical name to an + * identifier in an outer scope can lead to inadvertent errors if the incorrect + * identifier is modified. */ import cpp diff --git a/cpp/common/src/codingstandards/cpp/rules/identifierwithexternallinkageonedefinitionshared/IdentifierWithExternalLinkageOneDefinitionShared.qll b/cpp/common/src/codingstandards/cpp/rules/identifierwithexternallinkageonedefinitionshared/IdentifierWithExternalLinkageOneDefinitionShared.qll index 17808841eb..806315b43c 100644 --- a/cpp/common/src/codingstandards/cpp/rules/identifierwithexternallinkageonedefinitionshared/IdentifierWithExternalLinkageOneDefinitionShared.qll +++ b/cpp/common/src/codingstandards/cpp/rules/identifierwithexternallinkageonedefinitionshared/IdentifierWithExternalLinkageOneDefinitionShared.qll @@ -1,5 +1,7 @@ /** - * Provides a library which includes a `problems` predicate for reporting.... + * Provides a library with a `problems` predicate for the following issue: + * An identifier with multiple definitions in different translation units + * leads to undefined behavior. */ import cpp diff --git a/cpp/common/src/codingstandards/cpp/rules/ifelseterminationconstruct/IfElseTerminationConstruct.qll b/cpp/common/src/codingstandards/cpp/rules/ifelseterminationconstruct/IfElseTerminationConstruct.qll index 5755ed8f38..3c6f25e151 100644 --- a/cpp/common/src/codingstandards/cpp/rules/ifelseterminationconstruct/IfElseTerminationConstruct.qll +++ b/cpp/common/src/codingstandards/cpp/rules/ifelseterminationconstruct/IfElseTerminationConstruct.qll @@ -1,5 +1,6 @@ /** - * Provides a library which includes a `problems` predicate for reporting.... + * Provides a library with a `problems` predicate for the following issue: + * The final else statement is a defensive programming technique. */ import cpp diff --git a/cpp/common/src/codingstandards/cpp/rules/initializeallvirtualbaseclasses/InitializeAllVirtualBaseClasses.qll b/cpp/common/src/codingstandards/cpp/rules/initializeallvirtualbaseclasses/InitializeAllVirtualBaseClasses.qll new file mode 100644 index 0000000000..b3cfe203ac --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/initializeallvirtualbaseclasses/InitializeAllVirtualBaseClasses.qll @@ -0,0 +1,46 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * All constructors of a class should explicitly initialize all of its virtual base + * classes and immediate base classes. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.Constructor + +abstract class InitializeAllVirtualBaseClassesSharedQuery extends Query { } + +Query getQuery() { result instanceof InitializeAllVirtualBaseClassesSharedQuery } + +query predicate problems( + Constructor c, string message, Class declaringType, string declaringType_string, Class baseClass, + string baseClass_string +) { + exists(string type | + not isExcluded(c, getQuery()) and + declaringType = c.getDeclaringType() and + ( + declaringType.getABaseClass() = baseClass and type = "" + or + baseClass.(VirtualBaseClass).getAVirtuallyDerivedClass().getADerivedClass+() = declaringType and + type = " virtual" + ) and + // There is not an initializer on the constructor for this particular base class + not exists(ConstructorBaseClassInit init | + c.getAnInitializer() = init and + init.getInitializedClass() = baseClass and + not init.isCompilerGenerated() + ) and + // Must be a defined constructor + c.hasDefinition() and + // Not a compiler-generated constructor + not c.isCompilerGenerated() and + // Not a defaulted constructor + not c.isDefaulted() and + declaringType_string = declaringType.getSimpleName() and + baseClass_string = baseClass.getSimpleName() and + message = + "Constructor for $@ does not explicitly call constructor for" + type + " base class $@." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/initializerlistconstructoristheonlyconstructor/InitializerListConstructorIsTheOnlyConstructor.qll b/cpp/common/src/codingstandards/cpp/rules/initializerlistconstructoristheonlyconstructor/InitializerListConstructorIsTheOnlyConstructor.qll new file mode 100644 index 0000000000..e9579fcfba --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/initializerlistconstructoristheonlyconstructor/InitializerListConstructorIsTheOnlyConstructor.qll @@ -0,0 +1,65 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * A class shall only define an initializer-list constructor when it is the only + * constructor. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class InitializerListConstructorIsTheOnlyConstructorSharedQuery extends Query { } + +Query getQuery() { result instanceof InitializerListConstructorIsTheOnlyConstructorSharedQuery } + +class StdInitializerList extends Class { + StdInitializerList() { hasQualifiedName("std", "initializer_list") } +} + +/** + * An _initializer-list constructor_ according to `[dcl.init.list]`. + * + * A `Constructor` where the first parameter refers to `std::initializer_list`, and any remaining + * parameters have default arguments. + */ +class InitializerListConstructor extends Constructor { + InitializerListConstructor() { + // The first parameter is a `std::intializer_list` parameter + exists(Type firstParamType | firstParamType = getParameter(0).getType() | + // Either directly `std::initializer_list` + firstParamType instanceof StdInitializerList + or + //A reference to `std::initializer_list` + firstParamType.(ReferenceType).getBaseType().getUnspecifiedType() instanceof + StdInitializerList + ) and + // All parameters other than the fi + forall(Parameter other | other = getParameter([1 .. (getNumberOfParameters() - 1)]) | + exists(other.getInitializer()) + ) + } +} + +query predicate problems( + Constructor c, string message, InitializerListConstructor stdInitializerConstructor, + string stdInitializerConstructor_string +) { + exists(string paramList | + not isExcluded(c, getQuery()) and + // Not an initializer-list constructor + not c instanceof InitializerListConstructor and + // Constructor is not a special member function constructor + not c instanceof CopyConstructor and + not c instanceof MoveConstructor and + not c.getNumberOfParameters() = 0 and // default constructor + // And there is an initalizer-list constructor + stdInitializerConstructor = c.getDeclaringType().getAConstructor() and + // Determine the parameter type list of the constructor + paramList = + concat(string parameter | parameter = c.getAParameter().getType().getName() | parameter, ",") and + message = + "The constructor " + c.getQualifiedName() + "(" + paramList + + ") may be ignored in favour of $@ when using braced initialization." and + stdInitializerConstructor_string = "the constructor accepting std::initializer_list" + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/linesplicingusedincomments/LineSplicingUsedInComments.qll b/cpp/common/src/codingstandards/cpp/rules/linesplicingusedincomments/LineSplicingUsedInComments.qll new file mode 100644 index 0000000000..52dcf9a3f1 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/linesplicingusedincomments/LineSplicingUsedInComments.qll @@ -0,0 +1,19 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Entering a newline following a '\\' character can erroneously commenting out + * regions of code. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class LineSplicingUsedInCommentsSharedQuery extends Query { } + +Query getQuery() { result instanceof LineSplicingUsedInCommentsSharedQuery } + +query predicate problems(CppStyleComment c, string message) { + not isExcluded(c, getQuery()) and + exists(c.getContents().regexpFind("\\\n", _, _)) and + message = "C++ comment includes \\ as the last character of a line" +} diff --git a/cpp/common/src/codingstandards/cpp/rules/loopcompoundcondition/LoopCompoundCondition.qll b/cpp/common/src/codingstandards/cpp/rules/loopcompoundcondition/LoopCompoundCondition.qll new file mode 100644 index 0000000000..b71c193c8e --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/loopcompoundcondition/LoopCompoundCondition.qll @@ -0,0 +1,19 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * If the body of a loop is not enclosed in braces, then this can lead to incorrect + * execution, and hard for developers to maintain. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class LoopCompoundConditionSharedQuery extends Query { } + +Query getQuery() { result instanceof LoopCompoundConditionSharedQuery } + +query predicate problems(Loop loop, string message) { + not isExcluded(loop, getQuery()) and + not loop.getStmt() instanceof BlockStmt and + message = "Loop body not enclosed within braces." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.qll b/cpp/common/src/codingstandards/cpp/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.qll new file mode 100644 index 0000000000..b12cddba0b --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.qll @@ -0,0 +1,20 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * The lowercase form of L shall not be used as the first character in a literal + * suffix. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.Literals + +abstract class LowercaseLStartsInLiteralSuffixSharedQuery extends Query { } + +Query getQuery() { result instanceof LowercaseLStartsInLiteralSuffixSharedQuery } + +query predicate problems(IntegerLiteral l, string message) { + not isExcluded(l, getQuery()) and + exists(l.getValueText().indexOf("l")) and + message = "Lowercase 'l' used as a literal suffix." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/macrooffsetofused/MacroOffsetofUsed.qll b/cpp/common/src/codingstandards/cpp/rules/macrooffsetofused/MacroOffsetofUsed.qll new file mode 100644 index 0000000000..b475dc655e --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/macrooffsetofused/MacroOffsetofUsed.qll @@ -0,0 +1,18 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * The macro offsetof shall not be used. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class MacroOffsetofUsedSharedQuery extends Query { } + +Query getQuery() { result instanceof MacroOffsetofUsedSharedQuery } + +query predicate problems(MacroInvocation mi, string message) { + not isExcluded(mi, getQuery()) and + mi.getMacroName() = "offsetof" and + message = "Use of banned macro " + mi.getMacroName() + "." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/macroparameterfollowinghash/MacroParameterFollowingHash.qll b/cpp/common/src/codingstandards/cpp/rules/macroparameterfollowinghash/MacroParameterFollowingHash.qll new file mode 100644 index 0000000000..ae20368e67 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/macroparameterfollowinghash/MacroParameterFollowingHash.qll @@ -0,0 +1,24 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * A macro parameter immediately following a # operator shall not be immediately + * followed by a ## operator. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.Macro + +abstract class MacroParameterFollowingHashSharedQuery extends Query { } + +Query getQuery() { result instanceof MacroParameterFollowingHashSharedQuery } + +query predicate problems(Macro m, string message) { + not isExcluded(m, getQuery()) and + exists(StringizingOperator one, TokenPastingOperator two | + one.getMacro() = m and + two.getMacro() = m and + one.getOffset() < two.getOffset() + ) and + message = "Macro definition uses an # operator followed by a ## operator." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/macroparameternotenclosedinparentheses/MacroParameterNotEnclosedInParentheses.qll b/cpp/common/src/codingstandards/cpp/rules/macroparameternotenclosedinparentheses/MacroParameterNotEnclosedInParentheses.qll index 693ae36906..314d1dbe4c 100644 --- a/cpp/common/src/codingstandards/cpp/rules/macroparameternotenclosedinparentheses/MacroParameterNotEnclosedInParentheses.qll +++ b/cpp/common/src/codingstandards/cpp/rules/macroparameternotenclosedinparentheses/MacroParameterNotEnclosedInParentheses.qll @@ -1,5 +1,8 @@ /** - * Provides a library which includes a `problems` predicate for reporting.... + * Provides a library with a `problems` predicate for the following issue: + * In the definition of a function-like macro, each instance of a parameter + * shall be enclosed in parentheses, otherwise the result of preprocessor macro + * substitition may not be as expected. */ import cpp diff --git a/cpp/common/src/codingstandards/cpp/rules/multipleglobalormemberdeclarators/MultipleGlobalOrMemberDeclarators.qll b/cpp/common/src/codingstandards/cpp/rules/multipleglobalormemberdeclarators/MultipleGlobalOrMemberDeclarators.qll new file mode 100644 index 0000000000..05821d7270 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/multipleglobalormemberdeclarators/MultipleGlobalOrMemberDeclarators.qll @@ -0,0 +1,66 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * A declaration should not declare more than one variable or member variable. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class MultipleGlobalOrMemberDeclaratorsSharedQuery extends Query { } + +Query getQuery() { result instanceof MultipleGlobalOrMemberDeclaratorsSharedQuery } + +/* + * Unfortunately, we do not have an equivalent of `DeclStmt` for non-local declarations, so we + * cannot determine whether a declaration was declared with another declaration. + * + * However, we can use location trickery to figure out if the declaration occurs close enough to + * another declaration that it _must_ have been declared within the same declaration sequence. + * + * We do this by requiring that the end location of a previous declaration is within a certain + * number of characters of the start location of the current declaration. + */ + +/** + * A `Declaration` which is not in a local scope, and is written directly by the user. + * + * These act as "candidates" for declarations that could plausibly occur in a declaration sequence + * with other candidates. + */ +class NonLocalUserDeclaration extends Declaration { + NonLocalUserDeclaration() { + not this instanceof StackVariable and + not this instanceof TemplateParameter and + not this instanceof EnumConstant and + not this instanceof TypedefType and + not any(LambdaCapture lc).getField() = this and + not this.(Function).isCompilerGenerated() and + not this.(Variable).isCompilerGenerated() and + not this.(Parameter).getFunction().isCompilerGenerated() and + not this.isInMacroExpansion() and + not exists(Struct s, TypedefType t | + s.isAnonymous() and + t.getBaseType() = s and + this = s.getAMemberVariable() + ) + } +} + +/** + * Holds if `d1` is followed directly by `d2`. + */ +predicate isFollowingDeclaration(NonLocalUserDeclaration d1, NonLocalUserDeclaration d2) { + exists(string filepath, int startline, int startcolumn, int endline, int endcolumn | + d1.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and + d2.getLocation().hasLocationInfo(filepath, startline, endcolumn + [2 .. 3], endline, _) + ) and + not d1.(UserType).stripType() = d2.(Variable).getType().stripType() +} + +query predicate problems(NonLocalUserDeclaration d1, string message) { + not isExcluded(d1, getQuery()) and + isFollowingDeclaration(d1, _) and + not isFollowingDeclaration(_, d1) and + message = "Multiple declarations after " + d1.getName() + " in this declaration sequence." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/multiplelocaldeclarators/MultipleLocalDeclarators.qll b/cpp/common/src/codingstandards/cpp/rules/multiplelocaldeclarators/MultipleLocalDeclarators.qll new file mode 100644 index 0000000000..2269f36d97 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/multiplelocaldeclarators/MultipleLocalDeclarators.qll @@ -0,0 +1,20 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * A declaration should not declare more than one variable or member variable. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class MultipleLocalDeclaratorsSharedQuery extends Query { } + +Query getQuery() { result instanceof MultipleLocalDeclaratorsSharedQuery } + +query predicate problems(DeclStmt ds, string message) { + not isExcluded(ds, getQuery()) and + count(Declaration d | d = ds.getADeclaration()) > 1 and + // Not a compiler generated `DeclStmt`, such as in the range-based for loop + not ds.isCompilerGenerated() and + message = "Declaration list contains more than one declaration." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.qll b/cpp/common/src/codingstandards/cpp/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.qll new file mode 100644 index 0000000000..326886dda6 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.qll @@ -0,0 +1,20 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * A named bit-field with signed integer type shall not have a length of one bit. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class NamedBitFieldsWithSignedIntegerTypeSharedQuery extends Query { } + +Query getQuery() { result instanceof NamedBitFieldsWithSignedIntegerTypeSharedQuery } + +query predicate problems(BitField bitField, string message) { + not isExcluded(bitField, getQuery()) and + bitField.getDeclaredNumBits() = 1 and // Single-bit, + not bitField.isAnonymous() and // named, + bitField.getType().(IntegralType).isSigned() and // but its type is signed. + message = "A named bit-field with signed integral type should have at least 2 bits of storage." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/namenotreferredusingaqualifiedidorthis/NameNotReferredUsingAQualifiedIdOrThis.qll b/cpp/common/src/codingstandards/cpp/rules/namenotreferredusingaqualifiedidorthis/NameNotReferredUsingAQualifiedIdOrThis.qll new file mode 100644 index 0000000000..a4c9255c89 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/namenotreferredusingaqualifiedidorthis/NameNotReferredUsingAQualifiedIdOrThis.qll @@ -0,0 +1,37 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Not using a qualified-id or `this->` syntax for identifiers used in a class template + * makes the code more difficult to understand. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.NameInDependentBase + +abstract class NameNotReferredUsingAQualifiedIdOrThisSharedQuery extends Query { } + +Query getQuery() { result instanceof NameNotReferredUsingAQualifiedIdOrThisSharedQuery } + +query predicate problems( + NameQualifiableElement fn, string message, Element actualTarget, string targetName, + Element dependentTypeMemberWithSameName, string dependentType_string +) { + not isExcluded(fn, getQuery()) and + missingNameQualifier(fn) and + exists(TemplateClass c | + fn = getConfusingFunctionAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName) + or + fn = getConfusingFunctionCall(c, targetName, actualTarget, dependentTypeMemberWithSameName) and + not exists(Expr e | e = fn.(FunctionCall).getQualifier()) + or + fn = + getConfusingMemberVariableAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName) and + not exists(Expr e | e = fn.(VariableAccess).getQualifier()) + ) and + not fn.isAffectedByMacro() and + message = + "Use of unqualified identifier " + targetName + + " targets $@ but a member with the name also exists $@." and + dependentType_string = "in the dependent base class" +} diff --git a/cpp/common/src/codingstandards/cpp/rules/namenotreferredusingaqualifiedidorthisaudit/NameNotReferredUsingAQualifiedIdOrThisAudit.qll b/cpp/common/src/codingstandards/cpp/rules/namenotreferredusingaqualifiedidorthisaudit/NameNotReferredUsingAQualifiedIdOrThisAudit.qll new file mode 100644 index 0000000000..d0a6251908 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/namenotreferredusingaqualifiedidorthisaudit/NameNotReferredUsingAQualifiedIdOrThisAudit.qll @@ -0,0 +1,38 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Not using a qualified-id or `this->` syntax for identifiers used in a class template + * makes the code more difficult to understand. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.NameInDependentBase + +abstract class NameNotReferredUsingAQualifiedIdOrThisAuditSharedQuery extends Query { } + +Query getQuery() { result instanceof NameNotReferredUsingAQualifiedIdOrThisAuditSharedQuery } + +query predicate problems( + NameQualifiableElement fn, string message, Element actualTarget, string targetName, + Element dependentTypeMemberWithSameName, string dependentType_string +) { + not isExcluded(fn, getQuery()) and + not isCustomExcluded(fn) and + missingNameQualifier(fn) and + exists(TemplateClass c | + fn = getConfusingFunctionAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName) + or + fn = getConfusingFunctionCall(c, targetName, actualTarget, dependentTypeMemberWithSameName) and + not exists(Expr e | e = fn.(FunctionCall).getQualifier()) + or + not fn.(VariableAccess).getTarget() instanceof Parameter and + fn = + getConfusingMemberVariableAccess(c, targetName, actualTarget, dependentTypeMemberWithSameName) and + not exists(Expr e | e = fn.(VariableAccess).getQualifier()) + ) and + message = + "Use of unqualified identifier " + targetName + + " targets $@ but a member with the name also exists $@." and + dependentType_string = "in the dependent base class" +} diff --git a/cpp/common/src/codingstandards/cpp/rules/noexceptfunctionshouldnotpropagatetothecaller/NoexceptFunctionShouldNotPropagateToTheCaller.qll b/cpp/common/src/codingstandards/cpp/rules/noexceptfunctionshouldnotpropagatetothecaller/NoexceptFunctionShouldNotPropagateToTheCaller.qll new file mode 100644 index 0000000000..bc3b620718 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/noexceptfunctionshouldnotpropagatetothecaller/NoexceptFunctionShouldNotPropagateToTheCaller.qll @@ -0,0 +1,38 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * If a function is declared to be noexcept, noexcept(true) or noexcept(), then it shall not exit with an exception. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.exceptions.ExceptionFlow +import ExceptionPathGraph +import codingstandards.cpp.exceptions.ExceptionSpecifications + +abstract class NoexceptFunctionShouldNotPropagateToTheCallerSharedQuery extends Query { } + +Query getQuery() { result instanceof NoexceptFunctionShouldNotPropagateToTheCallerSharedQuery } + +class NoExceptThrowingFunction extends ExceptionThrowingFunction { + NoExceptThrowingFunction() { + // Can exit with an exception + exists(getAFunctionThrownType(_, _)) and + // But is marked noexcept(true) or equivalent + isNoExceptTrue(this) + } +} + +query predicate problems( + NoExceptThrowingFunction f, ExceptionFlowNode exceptionSource, ExceptionFlowNode functionNode, + string message +) { + exists(ExceptionType exceptionType | + not isExcluded(f, getQuery()) and + f.hasExceptionFlow(exceptionSource, functionNode, exceptionType) and + message = + "Function " + f.getName() + " is declared noexcept(true) but can throw exceptions of type " + + exceptionType.getExceptionName() + "." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/nonglobalfunctionmain/NonGlobalFunctionMain.qll b/cpp/common/src/codingstandards/cpp/rules/nonglobalfunctionmain/NonGlobalFunctionMain.qll new file mode 100644 index 0000000000..7366849d0c --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/nonglobalfunctionmain/NonGlobalFunctionMain.qll @@ -0,0 +1,20 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * The identifier main shall not be used for a function other than the global function + * main. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class NonGlobalFunctionMainSharedQuery extends Query { } + +Query getQuery() { result instanceof NonGlobalFunctionMainSharedQuery } + +query predicate problems(Function f, string message) { + not isExcluded(f, getQuery()) and + f.hasName("main") and + not f.hasGlobalName("main") and + message = "Identifier main used for a function other than the global function main." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.qll b/cpp/common/src/codingstandards/cpp/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.qll new file mode 100644 index 0000000000..f23965ea7c --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.qll @@ -0,0 +1,44 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Octal escape sequences, hexadecimal escape sequences, and universal character names + * shall be terminated. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class NonTerminatedEscapeSequencesSharedQuery extends Query { } + +Query getQuery() { result instanceof NonTerminatedEscapeSequencesSharedQuery } + +bindingset[s] +predicate isOctalEscape(string s) { + s.charAt(0) = "\\" and + exists(int i | i = [0 .. 7] | i.toString() = s.charAt(1)) +} + +bindingset[s] +predicate isHexEscape(string s) { s.indexOf("\\x") = 0 } + +query predicate problems(Literal l, string message) { + not isExcluded(l, getQuery()) and + exists(int idx, string sl, string escapeKind, string s | + sl = l.getValueText() and + idx = sl.indexOf("\\") and + s = sl.substring(idx, sl.length()) and + // Note: Octal representations must be 1-3 digits. There is no limitation on a + // Hex literal as long as the characters are valid. This query does not consider + // if the hex literal being constructed will overflow. + ( + isHexEscape(s) and + not s.regexpMatch("^((\\\\x[0-9A-F]+(?=[\"'\\\\])))[\\s\\S]*") and + escapeKind = "hexadecimal" + or + isOctalEscape(s) and + not s.regexpMatch("^(((\\\\[0-7]{1,3})(?=[\"'\\\\])))[\\s\\S]*") and + escapeKind = "octal" + ) and + message = "Invalid " + escapeKind + " escape in string literal at '" + s + "'." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.qll b/cpp/common/src/codingstandards/cpp/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.qll new file mode 100644 index 0000000000..f7afe8b3e7 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.qll @@ -0,0 +1,38 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Within an enumerator list, the value of an implicitly-specified enumeration constant + * shall be unique. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class NonUniqueEnumerationConstantSharedQuery extends Query { } + +Query getQuery() { result instanceof NonUniqueEnumerationConstantSharedQuery } + +/** + * An `EnumConstant` that has an implicitly specified value: + * `enum e { explicit = 1, implicit }` + */ +class ImplicitlySpecifiedEnumConstant extends EnumConstant { + ImplicitlySpecifiedEnumConstant() { + //implicitly specified have an initializer with location: `file://:0:0:0:0` + not this.getInitializer().getLocation().getFile() = this.getFile() + } +} + +query predicate problems( + ImplicitlySpecifiedEnumConstant imp, string message, EnumConstant exp, string exp_string +) { + not isExcluded(imp, getQuery()) and + not isExcluded(exp, getQuery()) and + not exp = imp and + imp.getValue() = exp.getValue() and + imp.getDeclaringEnum() = exp.getDeclaringEnum() and + //can technically be the same declared enum across multiple headers but those are not relevant to this rule + imp.getFile() = exp.getFile() and + message = "Nonunique value of enum constant compared to $@" and + exp_string = exp.getName() +} diff --git a/cpp/common/src/codingstandards/cpp/rules/notdistinctidentifier/NotDistinctIdentifier.qll b/cpp/common/src/codingstandards/cpp/rules/notdistinctidentifier/NotDistinctIdentifier.qll index 2d6767f664..093b804e0f 100644 --- a/cpp/common/src/codingstandards/cpp/rules/notdistinctidentifier/NotDistinctIdentifier.qll +++ b/cpp/common/src/codingstandards/cpp/rules/notdistinctidentifier/NotDistinctIdentifier.qll @@ -1,5 +1,6 @@ /** - * Provides a library which includes a `problems` predicate for reporting.... + * Provides a library with a `problems` predicate for the following issue: + * Using nondistinct external identifiers results in undefined behaviour. */ import cpp diff --git a/cpp/common/src/codingstandards/cpp/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.qll b/cpp/common/src/codingstandards/cpp/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.qll new file mode 100644 index 0000000000..2b24aa9410 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.qll @@ -0,0 +1,25 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * nullptr shall be the only form of the null-pointer-constant. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import semmle.code.cpp.commons.NULL + +abstract class NullptrNotTheOnlyFormOfTheNullPointerConstantSharedQuery extends Query { } + +Query getQuery() { result instanceof NullptrNotTheOnlyFormOfTheNullPointerConstantSharedQuery } + +query predicate problems(Literal l, string message) { + not isExcluded(l, getQuery()) and // Not the type of the nullptr literal + not l.getType() instanceof NullPointerType and + // Converted to a pointer type + l.getConversion().getType().getUnspecifiedType() instanceof PointerType and + // Value of zero + l.getValue() = "0" and + // Not the StringLiteral "0" + not l instanceof StringLiteral and + message = l.getValueText() + " is used as the null-pointer-constant but is not nullptr." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/objectsdynamictypeusedfromconstructorordestructor/ObjectsDynamicTypeUsedFromConstructorOrDestructor.qll b/cpp/common/src/codingstandards/cpp/rules/objectsdynamictypeusedfromconstructorordestructor/ObjectsDynamicTypeUsedFromConstructorOrDestructor.qll new file mode 100644 index 0000000000..1303646ef5 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/objectsdynamictypeusedfromconstructorordestructor/ObjectsDynamicTypeUsedFromConstructorOrDestructor.qll @@ -0,0 +1,91 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * An object’s dynamic type shall not be used from within its constructor or + * destructor. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class ObjectsDynamicTypeUsedFromConstructorOrDestructorSharedQuery extends Query { } + +Query getQuery() { result instanceof ObjectsDynamicTypeUsedFromConstructorOrDestructorSharedQuery } + +predicate thisCall(FunctionCall c) { + c.getQualifier() instanceof ThisExpr or + c.getQualifier().(PointerDereferenceExpr).getChild(0) instanceof ThisExpr +} + +predicate virtualThisCall(FunctionCall c, Function overridingFunction) { + c.isVirtual() and + thisCall(c) and + overridingFunction = c.getTarget().(VirtualFunction).getAnOverridingFunction() +} + +class DynamicTypeExpr extends Expr { + DynamicTypeExpr() { + this instanceof TypeidOperator and + this.getEnclosingFunction().getDeclaringType().isPolymorphic() + or + this instanceof DynamicCast + or + virtualThisCall(this.(FunctionCall), _) + } +} + +/* + * Catch most cases: go into functions in the same class, but only catch direct + * references to "this". + */ + +predicate nonVirtualMemberFunction(MemberFunction mf, Class c) { + mf = c.getAMemberFunction() and + not mf instanceof Constructor and + not mf instanceof Destructor and + not mf.isVirtual() +} + +predicate callFromNonVirtual(MemberFunction source, Class c, MemberFunction targ) { + exists(FunctionCall fc | + fc.getEnclosingFunction() = source and fc.getTarget() = targ and thisCall(fc) + ) and + targ = c.getAMemberFunction() and + nonVirtualMemberFunction(source, c) +} + +predicate indirectlyInvokesDynamicTypeExpr(MemberFunction caller, DynamicTypeExpr target) { + target = + any(DynamicTypeExpr expr | + expr.getEnclosingFunction() = caller and + nonVirtualMemberFunction(caller, caller.getDeclaringType()) + ) + or + exists(MemberFunction mid | + indirectlyInvokesDynamicTypeExpr(mid, target) and + callFromNonVirtual(caller, caller.getDeclaringType(), mid) + ) +} + +query predicate problems( + DynamicTypeExpr expr, string explanation, MemberFunction mf, string mf_string +) { + not isExcluded(expr, getQuery()) and + ( + mf instanceof Constructor or + mf instanceof Destructor + ) and + mf_string = mf.getQualifiedName() and + exists(FunctionCall call | + mf = expr.getEnclosingFunction() and + explanation = "$@ uses the dynamic type of its own object." + or + mf != expr.getEnclosingFunction() and + mf = call.getEnclosingFunction() and + thisCall(call) and + indirectlyInvokesDynamicTypeExpr(call.getTarget(), expr) and + explanation = + "$@ calls " + call.getTarget().getQualifiedName() + + ", which uses the dynamic type of its own object." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/overridingshallspecifydifferentdefaultarguments/OverridingShallSpecifyDifferentDefaultArguments.qll b/cpp/common/src/codingstandards/cpp/rules/overridingshallspecifydifferentdefaultarguments/OverridingShallSpecifyDifferentDefaultArguments.qll new file mode 100644 index 0000000000..acfa177561 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/overridingshallspecifydifferentdefaultarguments/OverridingShallSpecifyDifferentDefaultArguments.qll @@ -0,0 +1,37 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Parameters in an overriding virtual function shall not specify different default + * arguments. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class OverridingShallSpecifyDifferentDefaultArgumentsSharedQuery extends Query { } + +Query getQuery() { result instanceof OverridingShallSpecifyDifferentDefaultArgumentsSharedQuery } + +query predicate problems(VirtualFunction f2, string message, VirtualFunction f1, string f1_string) { + not isExcluded(f2, getQuery()) and + not isExcluded(f1, getQuery()) and + f2 = f1.getAnOverridingFunction() and + exists(Parameter p1, Parameter p2 | + p1 = f1.getAParameter() and + p2 = f2.getParameter(p1.getIndex()) + | + if p1.hasInitializer() + then + // if there is no initializer + not p2.hasInitializer() + or + // if there is one and it doesn't match + not p1.getInitializer().getExpr().getValueText() = + p2.getInitializer().getExpr().getValueText() + else + // if p1 doesn't have an initializer p2 shouldn't either + p2.hasInitializer() + ) and + message = "Overriding function does not have the same default parameters as $@" and + f1_string = "overridden function" +} diff --git a/cpp/common/src/codingstandards/cpp/rules/potentiallyvirtualpointeronlycomparestonullptr/PotentiallyVirtualPointerOnlyComparesToNullptr.qll b/cpp/common/src/codingstandards/cpp/rules/potentiallyvirtualpointeronlycomparestonullptr/PotentiallyVirtualPointerOnlyComparesToNullptr.qll new file mode 100644 index 0000000000..667480a43a --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/potentiallyvirtualpointeronlycomparestonullptr/PotentiallyVirtualPointerOnlyComparesToNullptr.qll @@ -0,0 +1,32 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * A comparison of a potentially virtual pointer to member function shall only be with + * nullptr. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class PotentiallyVirtualPointerOnlyComparesToNullptrSharedQuery extends Query { } + +Query getQuery() { result instanceof PotentiallyVirtualPointerOnlyComparesToNullptrSharedQuery } + +query predicate problems( + EqualityOperation equalityComparison, string message, MemberFunction virtualFunction, + string virtualFunction_string, Expr otherOperand, string otherOperand_string +) { + not isExcluded(equalityComparison, getQuery()) and + exists(FunctionAccess accessOperand | + virtualFunction.isVirtual() and + equalityComparison.getAnOperand() = accessOperand and + accessOperand.getTarget() = virtualFunction and + otherOperand = equalityComparison.getAnOperand() and + not otherOperand = accessOperand and + not otherOperand.getType() instanceof NullPointerType and + message = + "A pointer to member virtual function $@ is tested for equality with non-null-pointer-constant $@." and + virtualFunction_string = virtualFunction.getName() and + otherOperand_string = otherOperand.toString() + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/predicatefunctionobjectsshouldnotbemutable/PredicateFunctionObjectsShouldNotBeMutable.qll b/cpp/common/src/codingstandards/cpp/rules/predicatefunctionobjectsshouldnotbemutable/PredicateFunctionObjectsShouldNotBeMutable.qll index a8b6ab7576..bf47c1f649 100644 --- a/cpp/common/src/codingstandards/cpp/rules/predicatefunctionobjectsshouldnotbemutable/PredicateFunctionObjectsShouldNotBeMutable.qll +++ b/cpp/common/src/codingstandards/cpp/rules/predicatefunctionobjectsshouldnotbemutable/PredicateFunctionObjectsShouldNotBeMutable.qll @@ -1,5 +1,7 @@ /** - * Provides a library which includes a `problems` predicate for reporting.... + * Provides a library with a `problems` predicate for the following issue: + * "Non-static data members or captured values of predicate function objects + * that are state related to this object's identity shall not be copied. */ import cpp diff --git a/cpp/common/src/codingstandards/cpp/rules/preprocessingdirectivewithinmacroargument/PreprocessingDirectiveWithinMacroArgument.qll b/cpp/common/src/codingstandards/cpp/rules/preprocessingdirectivewithinmacroargument/PreprocessingDirectiveWithinMacroArgument.qll index 8b8609ab7b..8361a07a31 100644 --- a/cpp/common/src/codingstandards/cpp/rules/preprocessingdirectivewithinmacroargument/PreprocessingDirectiveWithinMacroArgument.qll +++ b/cpp/common/src/codingstandards/cpp/rules/preprocessingdirectivewithinmacroargument/PreprocessingDirectiveWithinMacroArgument.qll @@ -1,5 +1,7 @@ /** - * Provides a library which includes a `problems` predicate for reporting.... + * Provides a library with a `problems` predicate for the following issue: + * Arguments to a function-like macro shall not contain tokens that look like + * pre-processing directives or else behaviour after macro expansion is unpredictable. */ import cpp diff --git a/cpp/common/src/codingstandards/cpp/rules/reinterpretcastused/ReinterpretCastUsed.qll b/cpp/common/src/codingstandards/cpp/rules/reinterpretcastused/ReinterpretCastUsed.qll new file mode 100644 index 0000000000..b49a488ab2 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/reinterpretcastused/ReinterpretCastUsed.qll @@ -0,0 +1,16 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * The statement reinterpret_cast shall not be used. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class ReinterpretCastUsedSharedQuery extends Query { } + +Query getQuery() { result instanceof ReinterpretCastUsedSharedQuery } + +query predicate problems(ReinterpretCast rc, string message) { + not isExcluded(rc, getQuery()) and message = "Use of reinterpret_cast." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.qll b/cpp/common/src/codingstandards/cpp/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.qll new file mode 100644 index 0000000000..04a106b5c4 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.qll @@ -0,0 +1,18 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * The result of an assignment operator should not be used. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class ResultOfAnAssignmentOperatorShouldNotBeUsedSharedQuery extends Query { } + +Query getQuery() { result instanceof ResultOfAnAssignmentOperatorShouldNotBeUsedSharedQuery } + +query predicate problems(AssignExpr e, string message) { + not isExcluded(e, getQuery()) and + not exists(ExprStmt s | s.getExpr() = e) and + message = "Use of an assignment operator's result." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/returnreferenceorpointertoautomaticlocalvariable/ReturnReferenceOrPointerToAutomaticLocalVariable.qll b/cpp/common/src/codingstandards/cpp/rules/returnreferenceorpointertoautomaticlocalvariable/ReturnReferenceOrPointerToAutomaticLocalVariable.qll new file mode 100644 index 0000000000..cd623f711c --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/returnreferenceorpointertoautomaticlocalvariable/ReturnReferenceOrPointerToAutomaticLocalVariable.qll @@ -0,0 +1,36 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Functions that return a reference or a pointer to an automatic variable (including + * parameters) potentially lead to undefined behaviour. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class ReturnReferenceOrPointerToAutomaticLocalVariableSharedQuery extends Query { } + +Query getQuery() { result instanceof ReturnReferenceOrPointerToAutomaticLocalVariableSharedQuery } + +query predicate problems( + ReturnStmt rs, string message, Function f, string f_string, Variable auto, string auto_string +) { + exists(VariableAccess va, string returnType | + not isExcluded(rs, getQuery()) and + f = rs.getEnclosingFunction() and + ( + f.getType() instanceof ReferenceType and va = rs.getExpr() and returnType = "reference" + or + f.getType() instanceof PointerType and + va = rs.getExpr().(AddressOfExpr).getOperand() and + returnType = "pointer" + ) and + auto = va.getTarget() and + not auto.isStatic() and + not f.isCompilerGenerated() and + not auto.getType() instanceof ReferenceType and + message = "The $@ returns a " + returnType + "to an $@ variable" and + f_string = f.getName() and + auto_string = "automatic" + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/switchcasepositioncondition/SwitchCasePositionCondition.qll b/cpp/common/src/codingstandards/cpp/rules/switchcasepositioncondition/SwitchCasePositionCondition.qll index 68ba9850af..979621762d 100644 --- a/cpp/common/src/codingstandards/cpp/rules/switchcasepositioncondition/SwitchCasePositionCondition.qll +++ b/cpp/common/src/codingstandards/cpp/rules/switchcasepositioncondition/SwitchCasePositionCondition.qll @@ -1,5 +1,6 @@ /** - * Provides a library which includes a `problems` predicate for reporting.... + * Provides a library with a `problems` predicate for the following issue: + * The switch statement syntax is weak and may lead to unspecified behaviour. */ import cpp diff --git a/cpp/common/src/codingstandards/cpp/rules/switchcompoundcondition/SwitchCompoundCondition.qll b/cpp/common/src/codingstandards/cpp/rules/switchcompoundcondition/SwitchCompoundCondition.qll new file mode 100644 index 0000000000..ab888abfec --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/switchcompoundcondition/SwitchCompoundCondition.qll @@ -0,0 +1,46 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * If the body of a switch is not enclosed in braces, then this can lead to incorrect + * execution, and hard for developers to maintain. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class SwitchCompoundConditionSharedQuery extends Query { } + +Query getQuery() { result instanceof SwitchCompoundConditionSharedQuery } + +/** + * Class to differentiate between extractor generated blockstmt and actual blockstmt. The extractor + * will generate an artificial blockstmt when there is a single case and statement, e.g. + * ``` + * switch(x) + * case 1: + * f(); + * ``` + * This is because our AST model considers the `case` to be a statement in its own right, so the + * extractor needs an aritifical block to hold both the case and the statement. + */ +class ArtificialBlock extends BlockStmt { + ArtificialBlock() { + exists(Location block, Location firstStatement | + block = getLocation() and firstStatement = getStmt(0).getLocation() + | + // We can identify artificial blocks as those where the start of the statement is at the same + // location as the start of the first statement in the block i.e. there was no opening brace. + block.getStartLine() = firstStatement.getStartLine() and + block.getStartColumn() = firstStatement.getStartColumn() + ) + } +} + +query predicate problems(SwitchStmt switch, string message) { + ( + switch.getStmt() instanceof ArtificialBlock or + not switch.getStmt() instanceof BlockStmt + ) and + not isExcluded(switch, getQuery()) and + message = "Switch body not enclosed within braces." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/switchnotwellformed/SwitchNotWellFormed.qll b/cpp/common/src/codingstandards/cpp/rules/switchnotwellformed/SwitchNotWellFormed.qll index ee04228a95..cb2e61c3ad 100644 --- a/cpp/common/src/codingstandards/cpp/rules/switchnotwellformed/SwitchNotWellFormed.qll +++ b/cpp/common/src/codingstandards/cpp/rules/switchnotwellformed/SwitchNotWellFormed.qll @@ -1,5 +1,6 @@ /** - * Provides a library which includes a `problems` predicate for reporting.... + * Provides a library with a `problems` predicate for the following issue: + * The switch statement syntax is weak and may lead to unspecified behaviour. */ import cpp diff --git a/cpp/common/src/codingstandards/cpp/rules/typeomitted/TypeOmitted.qll b/cpp/common/src/codingstandards/cpp/rules/typeomitted/TypeOmitted.qll index 8c1cb3b80a..0906a1de4f 100644 --- a/cpp/common/src/codingstandards/cpp/rules/typeomitted/TypeOmitted.qll +++ b/cpp/common/src/codingstandards/cpp/rules/typeomitted/TypeOmitted.qll @@ -1,5 +1,6 @@ /** - * Provides a library which includes a `problems` predicate for reporting.... + * Provides a library with a `problems` predicate for the following issue: + * Omission of type specifiers may not be supported by some compilers. */ import cpp diff --git a/cpp/common/src/codingstandards/cpp/rules/unsignedintegerliteralsnotappropriatelysuffixed/UnsignedIntegerLiteralsNotAppropriatelySuffixed.qll b/cpp/common/src/codingstandards/cpp/rules/unsignedintegerliteralsnotappropriatelysuffixed/UnsignedIntegerLiteralsNotAppropriatelySuffixed.qll new file mode 100644 index 0000000000..0b9ccb17f1 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/unsignedintegerliteralsnotappropriatelysuffixed/UnsignedIntegerLiteralsNotAppropriatelySuffixed.qll @@ -0,0 +1,29 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Unsigned integer literals shall be appropriately suffixed. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.Cpp14Literal + +abstract class UnsignedIntegerLiteralsNotAppropriatelySuffixedSharedQuery extends Query { } + +Query getQuery() { result instanceof UnsignedIntegerLiteralsNotAppropriatelySuffixedSharedQuery } + +query predicate problems(Cpp14Literal::NumericLiteral nl, string message) { + exists(string literalKind | + not isExcluded(nl, getQuery()) and + ( + nl instanceof Cpp14Literal::OctalLiteral and literalKind = "Octal" + or + nl instanceof Cpp14Literal::HexLiteral and literalKind = "Hex" + ) and + // This either directly has an unsigned integer type, or it is converted to an unsigned integer type + nl.getType().getUnspecifiedType().(IntegralType).isUnsigned() and + // The literal already has a `u` or `U` suffix. + not nl.getValueText().regexpMatch(".*[lL]*[uU][lL]*") and + message = literalKind + " literal is an unsigned integer but does not include a 'U' suffix." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.qll b/cpp/common/src/codingstandards/cpp/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.qll new file mode 100644 index 0000000000..bc0c6d8fc1 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.qll @@ -0,0 +1,33 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * An unsigned arithmetic operation with constant operands should not wrap. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.Overflow +import semmle.code.cpp.controlflow.Guards +import semmle.code.cpp.valuenumbering.GlobalValueNumbering + +abstract class UnsignedOperationWithConstantOperandsWrapsSharedQuery extends Query { } + +Query getQuery() { result instanceof UnsignedOperationWithConstantOperandsWrapsSharedQuery } + +query predicate problems(InterestingOverflowingOperation op, string message) { + not isExcluded(op, getQuery()) and + op.getType().getUnderlyingType().(IntegralType).isUnsigned() and + // Not within a guard condition + not exists(GuardCondition gc | gc.getAChild*() = op) and + // Not guarded by a check, where the check is not an invalid overflow check + not op.hasValidPreCheck() and + // Is not checked after the operation + not op.hasValidPostCheck() and + // Permitted by exception 3 + not op instanceof LShiftExpr and + // Permitted by exception 2 - zero case is handled in separate query + not op instanceof DivExpr and + not op instanceof RemExpr and + message = + "Operation " + op.getOperator() + " of type " + op.getType().getUnderlyingType() + " may wrap." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.qll b/cpp/common/src/codingstandards/cpp/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.qll new file mode 100644 index 0000000000..f5d1834723 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.qll @@ -0,0 +1,19 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * Octal constants shall not be used. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.Cpp14Literal + +abstract class UseOfNonZeroOctalLiteralSharedQuery extends Query { } + +Query getQuery() { result instanceof UseOfNonZeroOctalLiteralSharedQuery } + +query predicate problems(Cpp14Literal::OctalLiteral octalLiteral, string message) { + not isExcluded(octalLiteral, getQuery()) and + not octalLiteral.getValue() = "0" and + message = "Non zero octal literal " + octalLiteral.getValueText() + "." +} diff --git a/cpp/common/src/codingstandards/cpp/rules/vectorshouldnotbespecializedwithbool/VectorShouldNotBeSpecializedWithBool.qll b/cpp/common/src/codingstandards/cpp/rules/vectorshouldnotbespecializedwithbool/VectorShouldNotBeSpecializedWithBool.qll new file mode 100644 index 0000000000..ca23306c55 --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/vectorshouldnotbespecializedwithbool/VectorShouldNotBeSpecializedWithBool.qll @@ -0,0 +1,36 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * The std::vector specialization differs from all other containers + * std::vector such that sizeof bool is implementation defined which causes errors + * when using some STL algorithms. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions +import codingstandards.cpp.StdNamespace + +abstract class VectorShouldNotBeSpecializedWithBoolSharedQuery extends Query { } + +Query getQuery() { result instanceof VectorShouldNotBeSpecializedWithBoolSharedQuery } + +predicate isVectorBool(ClassTemplateInstantiation c) { + c.getNamespace() instanceof StdNS and + c.getTemplateArgument(0) instanceof BoolType and + c.getSimpleName() = "vector" +} + +predicate isUsingVectorBool(ClassTemplateInstantiation c) { + isVectorBool(c) or + isUsingVectorBool(c.getTemplateArgument(_)) +} + +query predicate problems(Variable v, string message) { + exists(ClassTemplateInstantiation c | + not isExcluded(v, getQuery()) and + v.getUnderlyingType() = c and + not v.isFromTemplateInstantiation(_) and + isUsingVectorBool(c) and + message = "Use of std::vector specialization." + ) +} diff --git a/cpp/common/src/codingstandards/cpp/rules/virtualandnonvirtualclassinthehierarchy/VirtualAndNonVirtualClassInTheHierarchy.qll b/cpp/common/src/codingstandards/cpp/rules/virtualandnonvirtualclassinthehierarchy/VirtualAndNonVirtualClassInTheHierarchy.qll new file mode 100644 index 0000000000..f29d69d1ac --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/virtualandnonvirtualclassinthehierarchy/VirtualAndNonVirtualClassInTheHierarchy.qll @@ -0,0 +1,40 @@ +/** + * Provides a library with a `problems` predicate for the following issue: + * An accessible base class shall not be both virtual and non-virtual in the same + * hierarchy. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +abstract class VirtualAndNonVirtualClassInTheHierarchySharedQuery extends Query { } + +Query getQuery() { result instanceof VirtualAndNonVirtualClassInTheHierarchySharedQuery } + +query predicate problems( + Class c3, string message, Class base, string base_string, ClassDerivation cd1, string cd1_string, + Class c2, string c2_string +) { + exists(Class c1, ClassDerivation cd2 | + not isExcluded(c3, getQuery()) and + // for each pair of classes, get all of their derivations + cd1 = c1.getADerivation() and + cd2 = c2.getADerivation() and + // where they share the same base class + base = cd1.getBaseClass() and + base = cd2.getBaseClass() and + // but one is virtual, and one is not, and the derivations are in different classes + cd1.isVirtual() and + not cd2.isVirtual() and + // and there is some 'other class' that derives from both of these classes + c3.derivesFrom*(c1) and + c3.derivesFrom*(c2) and + // and the base class is accessible from the 'other class' + c3.getAMemberFunction().getEnclosingAccessHolder().canAccessClass(base, c3) and + message = "Class inherits base class $@, which is derived virtual by $@ and non-virtual by $@." and + base_string = base.getName() and + cd1_string = cd1.getDerivedClass().toString() and + c2_string = cd2.getDerivedClass().toString() + ) +} diff --git a/cpp/common/test/includes/standard-library/assert.h b/cpp/common/test/includes/standard-library/assert.h index e69de29bb2..e8ba88d635 100644 --- a/cpp/common/test/includes/standard-library/assert.h +++ b/cpp/common/test/includes/standard-library/assert.h @@ -0,0 +1,6 @@ +#ifndef _GHLIBCPP_ASSERT +#define _GHLIBCPP_ASSERT + +#define assert(x) (void)0 + +#endif // _GHLIBCPP_ASSERT \ No newline at end of file diff --git a/cpp/common/test/includes/standard-library/cassert b/cpp/common/test/includes/standard-library/cassert index e69de29bb2..0477057664 100644 --- a/cpp/common/test/includes/standard-library/cassert +++ b/cpp/common/test/includes/standard-library/cassert @@ -0,0 +1 @@ +#include "assert.h" \ No newline at end of file diff --git a/cpp/common/test/includes/standard-library/ctime b/cpp/common/test/includes/standard-library/ctime index f99aab4fb3..9448e0615e 100644 --- a/cpp/common/test/includes/standard-library/ctime +++ b/cpp/common/test/includes/standard-library/ctime @@ -1,39 +1,17 @@ #ifndef _GHLIBCPP_CTIME #define _GHLIBCPP_CTIME - -namespace std -{ - typedef unsigned long clock_t; - typedef unsigned long time_t; - - typedef unsigned long size_t; - struct tm - { - int tm_sec; - int tm_min; - int tm_hour; - int tm_mday; - int tm_mon; - int tm_year; - int tm_wday; - int tm_yday; - int tm_isdst; - }; - - - clock_t clock (void); - double difftime (clock_t end, clock_t beginning); - time_t mktime (struct tm * timeptr); - time_t time (time_t* timer); - char* asctime (const struct tm * timeptr); - - char* ctime (const time_t * timer); - struct tm * gmtime (const time_t * timer); - struct tm * localtime (const time_t * timer); - size_t strftime (char* ptr, size_t maxsize, const char* format, - const struct tm* timeptr ); - -} - - -#endif \ No newline at end of file +#include +namespace std { +using ::clock_t; +using ::clock; +using ::time_t; +using ::time; +using ::tm; +using ::difftime; +using ::asctime; +using ::ctime; +using ::localtime; +using ::gmtime; +using ::mktime; +} // namespace std +#endif // _GHLIBCPP_CTIME \ No newline at end of file diff --git a/cpp/common/test/includes/standard-library/locale.h b/cpp/common/test/includes/standard-library/locale.h index 346c4eeef5..19a8905531 100644 --- a/cpp/common/test/includes/standard-library/locale.h +++ b/cpp/common/test/includes/standard-library/locale.h @@ -1,8 +1,38 @@ #ifndef _GHLIBCPP_LOCALE #define _GHLIBCPP_LOCALE -struct lconv; -char *setlocale(int, const char *); -lconv *localeconv(); +#define LC_ALL 6 + +struct lconv { + char *decimal_point; + char *thousands_sep; + char *grouping; + + char *int_curr_symbol; + char *currency_symbol; + char *mon_decimal_point; + char *mon_thousands_sep; + char *mon_grouping; + char *positive_sign; + char *negative_sign; + char int_frac_digits; + char frac_digits; + char p_cs_precedes; + char p_sep_by_space; + char n_cs_precedes; + char n_sep_by_space; + char p_sign_posn; + char n_sign_posn; + char int_p_cs_precedes; + char int_p_sep_by_space; + char int_n_cs_precedes; + char int_n_sep_by_space; + char int_p_sign_posn; + char int_n_sign_posn; +}; + + +char *setlocale (int, const char *); +struct lconv *localeconv(void); #endif // _GHLIBCPP_LOCALE \ No newline at end of file diff --git a/cpp/common/test/includes/standard-library/stddef.h b/cpp/common/test/includes/standard-library/stddef.h index 496de53167..96e9849973 100644 --- a/cpp/common/test/includes/standard-library/stddef.h +++ b/cpp/common/test/includes/standard-library/stddef.h @@ -17,5 +17,11 @@ using size_t = decltype(sizeof(char)); #define offsetof(t, d) __builtin_offsetof(t, d) /*implementation-defined*/ +#ifdef __cplusplus +#define NULL 0L +#else +#define NULL ((void*)0) +#endif + // namespace std #endif // _GHLIBCPP_STDDEF \ No newline at end of file diff --git a/cpp/common/test/includes/standard-library/stdlib.h b/cpp/common/test/includes/standard-library/stdlib.h index c8ff7a7592..67f1abd694 100644 --- a/cpp/common/test/includes/standard-library/stdlib.h +++ b/cpp/common/test/includes/standard-library/stdlib.h @@ -15,6 +15,8 @@ int system(const char *command); char *getenv(const char *name); +int setenv (const char *, const char *, int); + int atoi(const char *str); long int atol(const char *str); long long int atoll(const char *str); diff --git a/cpp/common/test/includes/standard-library/string.h b/cpp/common/test/includes/standard-library/string.h index c4d06b6e7b..d94a186f0e 100644 --- a/cpp/common/test/includes/standard-library/string.h +++ b/cpp/common/test/includes/standard-library/string.h @@ -36,6 +36,8 @@ char *strstr(char *str1, const char *str2); char *strtok(char *str, const char *delimiters); +char *strdup (const char *); + void *memcpy(void *dest, const void *src, size_t count); void *memset(void *dest, int ch, size_t count); void *memmove(void *dest, const void *src, size_t count); diff --git a/cpp/common/test/includes/standard-library/time.h b/cpp/common/test/includes/standard-library/time.h index e69de29bb2..cc7ff1673a 100644 --- a/cpp/common/test/includes/standard-library/time.h +++ b/cpp/common/test/includes/standard-library/time.h @@ -0,0 +1,32 @@ +#ifndef _GHLIBCPP_TIME +#define _GHLIBCPP_TIME + +typedef unsigned long clock_t; +typedef unsigned long time_t; + +typedef unsigned long size_t; +struct tm { + int tm_sec; + int tm_min; + int tm_hour; + int tm_mday; + int tm_mon; + int tm_year; + int tm_wday; + int tm_yday; + int tm_isdst; +}; + +clock_t clock(void); +double difftime(clock_t end, clock_t beginning); +time_t mktime(struct tm *timeptr); +time_t time(time_t *timer); +char *asctime(const struct tm *timeptr); + +char *ctime(const time_t *timer); +struct tm *gmtime(const time_t *timer); +struct tm *localtime(const time_t *timer); +size_t strftime(char *ptr, size_t maxsize, const char *format, + const struct tm *timeptr); + +#endif // _GHLIBCPP_TIME \ No newline at end of file diff --git a/cpp/autosar/test/rules/M5-3-3/UnaryOperatorOverloaded.expected b/cpp/common/test/rules/addressofoperatoroverloaded/AddressOfOperatorOverloaded.expected similarity index 100% rename from cpp/autosar/test/rules/M5-3-3/UnaryOperatorOverloaded.expected rename to cpp/common/test/rules/addressofoperatoroverloaded/AddressOfOperatorOverloaded.expected diff --git a/cpp/common/test/rules/addressofoperatoroverloaded/AddressOfOperatorOverloaded.ql b/cpp/common/test/rules/addressofoperatoroverloaded/AddressOfOperatorOverloaded.ql new file mode 100644 index 0000000000..ee8ba0d5d5 --- /dev/null +++ b/cpp/common/test/rules/addressofoperatoroverloaded/AddressOfOperatorOverloaded.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.addressofoperatoroverloaded.AddressOfOperatorOverloaded + +class TestFileQuery extends AddressOfOperatorOverloadedSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/M5-3-3/test.cpp b/cpp/common/test/rules/addressofoperatoroverloaded/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M5-3-3/test.cpp rename to cpp/common/test/rules/addressofoperatoroverloaded/test.cpp diff --git a/cpp/common/test/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.expected b/cpp/common/test/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.expected new file mode 100644 index 0000000000..71355bf4cc --- /dev/null +++ b/cpp/common/test/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.expected @@ -0,0 +1,2 @@ +| test.cpp:5:1:5:41 | #define BAD_MACRO_WITH_ARG(x) (x) + wow ## x | Macro BAD_MACRO_WITH_ARG contains use of parameter x used in multiple contexts. | +| test.cpp:6:1:6:48 | #define BAD_MACRO_WITH_ARG_TWO(x,y) (x) + wow ## x | Macro BAD_MACRO_WITH_ARG_TWO contains use of parameter x used in multiple contexts. | diff --git a/cpp/common/test/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.ql b/cpp/common/test/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.ql new file mode 100644 index 0000000000..5aa514e86d --- /dev/null +++ b/cpp/common/test/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.amixedusemacroargumentsubjecttoexpansion.AMixedUseMacroArgumentSubjectToExpansion + +class TestFileQuery extends AMixedUseMacroArgumentSubjectToExpansionSharedQuery, TestQuery { } diff --git a/c/misra/test/rules/RULE-20-12/test.c b/cpp/common/test/rules/amixedusemacroargumentsubjecttoexpansion/test.cpp similarity index 86% rename from c/misra/test/rules/RULE-20-12/test.c rename to cpp/common/test/rules/amixedusemacroargumentsubjecttoexpansion/test.cpp index 768238f36d..e96e2f7414 100644 --- a/c/misra/test/rules/RULE-20-12/test.c +++ b/cpp/common/test/rules/amixedusemacroargumentsubjecttoexpansion/test.cpp @@ -1,4 +1,5 @@ - +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. #define GOOD_MACRO_WITH_ARG(X) ((X)*X##_scale) // COMPLIANT #define MACRO 1 #define BAD_MACRO_WITH_ARG(x) (x) + wow##x // NON_COMPLIANT diff --git a/cpp/autosar/test/rules/M5-2-12/IdentifierWithArrayTypePassedAsFunctionArgumentDecayToAPointer.expected b/cpp/common/test/rules/arraypassedasfunctionargumentdecaytoapointer/ArrayPassedAsFunctionArgumentDecayToAPointer.expected similarity index 100% rename from cpp/autosar/test/rules/M5-2-12/IdentifierWithArrayTypePassedAsFunctionArgumentDecayToAPointer.expected rename to cpp/common/test/rules/arraypassedasfunctionargumentdecaytoapointer/ArrayPassedAsFunctionArgumentDecayToAPointer.expected diff --git a/cpp/common/test/rules/arraypassedasfunctionargumentdecaytoapointer/ArrayPassedAsFunctionArgumentDecayToAPointer.ql b/cpp/common/test/rules/arraypassedasfunctionargumentdecaytoapointer/ArrayPassedAsFunctionArgumentDecayToAPointer.ql new file mode 100644 index 0000000000..929e5affdf --- /dev/null +++ b/cpp/common/test/rules/arraypassedasfunctionargumentdecaytoapointer/ArrayPassedAsFunctionArgumentDecayToAPointer.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.arraypassedasfunctionargumentdecaytoapointer.ArrayPassedAsFunctionArgumentDecayToAPointer + +class TestFileQuery extends ArrayPassedAsFunctionArgumentDecayToAPointerSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/M5-2-12/test.cpp b/cpp/common/test/rules/arraypassedasfunctionargumentdecaytoapointer/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M5-2-12/test.cpp rename to cpp/common/test/rules/arraypassedasfunctionargumentdecaytoapointer/test.cpp diff --git a/cpp/autosar/test/rules/A7-4-1/AsmDeclarationUsed.expected b/cpp/common/test/rules/asmdeclarationused/AsmDeclarationUsed.expected similarity index 100% rename from cpp/autosar/test/rules/A7-4-1/AsmDeclarationUsed.expected rename to cpp/common/test/rules/asmdeclarationused/AsmDeclarationUsed.expected diff --git a/cpp/common/test/rules/asmdeclarationused/AsmDeclarationUsed.ql b/cpp/common/test/rules/asmdeclarationused/AsmDeclarationUsed.ql new file mode 100644 index 0000000000..5e60570f5a --- /dev/null +++ b/cpp/common/test/rules/asmdeclarationused/AsmDeclarationUsed.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.asmdeclarationused.AsmDeclarationUsed + +class TestFileQuery extends AsmDeclarationUsedSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/A7-4-1/test.cpp b/cpp/common/test/rules/asmdeclarationused/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A7-4-1/test.cpp rename to cpp/common/test/rules/asmdeclarationused/test.cpp diff --git a/cpp/common/test/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.expected b/cpp/common/test/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.expected new file mode 100644 index 0000000000..9a849af3f4 --- /dev/null +++ b/cpp/common/test/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.expected @@ -0,0 +1,4 @@ +| test.cpp:8:14:8:17 | call to atof | Call to banned function atof. | +| test.cpp:9:12:9:15 | call to atoi | Call to banned function atoi. | +| test.cpp:10:13:10:16 | call to atol | Call to banned function atol. | +| test.cpp:11:18:11:22 | call to atoll | Call to banned function atoll. | diff --git a/cpp/common/test/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.ql b/cpp/common/test/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.ql new file mode 100644 index 0000000000..6da5fe6097 --- /dev/null +++ b/cpp/common/test/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.atofatoiatolandatollused.AtofAtoiAtolAndAtollUsed + +class TestFileQuery extends AtofAtoiAtolAndAtollUsedSharedQuery, TestQuery { } diff --git a/c/misra/test/rules/RULE-21-7/test.c b/cpp/common/test/rules/atofatoiatolandatollused/test.cpp similarity index 66% rename from c/misra/test/rules/RULE-21-7/test.c rename to cpp/common/test/rules/atofatoiatolandatollused/test.cpp index 141dd061d3..c995df6aad 100644 --- a/c/misra/test/rules/RULE-21-7/test.c +++ b/cpp/common/test/rules/atofatoiatolandatollused/test.cpp @@ -1,8 +1,10 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. #include #include void f2(); void f1() { - char l1[5] = "abcde"; + char l1[5] = "abcd"; float l2 = atof(l1); // NON_COMLIANT int l3 = atoi(l1); // NON_COMPLIANT long l4 = atol(l1); // NON_COMPLIANT diff --git a/cpp/autosar/test/rules/A2-13-1/EscapeSequenceOutsideISO.expected b/cpp/common/test/rules/backslashcharactermisuse/BackslashCharacterMisuse.expected similarity index 100% rename from cpp/autosar/test/rules/A2-13-1/EscapeSequenceOutsideISO.expected rename to cpp/common/test/rules/backslashcharactermisuse/BackslashCharacterMisuse.expected diff --git a/cpp/common/test/rules/backslashcharactermisuse/BackslashCharacterMisuse.ql b/cpp/common/test/rules/backslashcharactermisuse/BackslashCharacterMisuse.ql new file mode 100644 index 0000000000..aa32fa3096 --- /dev/null +++ b/cpp/common/test/rules/backslashcharactermisuse/BackslashCharacterMisuse.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.backslashcharactermisuse.BackslashCharacterMisuse + +class TestFileQuery extends BackslashCharacterMisuseSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/A2-13-1/test.cpp b/cpp/common/test/rules/backslashcharactermisuse/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A2-13-1/test.cpp rename to cpp/common/test/rules/backslashcharactermisuse/test.cpp diff --git a/cpp/common/test/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.expected b/cpp/common/test/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.expected new file mode 100644 index 0000000000..346a557e32 --- /dev/null +++ b/cpp/common/test/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.expected @@ -0,0 +1,4 @@ +| test.cpp:9:7:9:8 | x1 | Bit-field 'x1' is declared on type 'int'. | +| test.cpp:13:15:13:16 | x5 | Bit-field 'x5' is declared on type 'signed long'. | +| test.cpp:15:15:15:16 | x6 | Bit-field 'x6' is declared on type 'signed char'. | +| test.cpp:17:14:17:15 | x7 | Bit-field 'x7' is declared on type 'Color'. | diff --git a/cpp/common/test/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.ql b/cpp/common/test/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.ql new file mode 100644 index 0000000000..a3e1ecc76c --- /dev/null +++ b/cpp/common/test/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.bitfieldshallhaveanappropriatetype.BitFieldShallHaveAnAppropriateType + +class TestFileQuery extends BitFieldShallHaveAnAppropriateTypeSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/bitfieldshallhaveanappropriatetype/test.cpp b/cpp/common/test/rules/bitfieldshallhaveanappropriatetype/test.cpp new file mode 100644 index 0000000000..96b28997c4 --- /dev/null +++ b/cpp/common/test/rules/bitfieldshallhaveanappropriatetype/test.cpp @@ -0,0 +1,18 @@ + +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +typedef unsigned int UINT16; + +enum Color { R, G, B }; + +struct SampleStruct { + int x1 : 2; // NON_COMPLIANT - not explicitly signed or unsigned + unsigned int x2 : 2; // COMPLIANT - explicitly unsigned + signed int x3 : 2; // COMPLIANT - explicitly signed + UINT16 x4 : 2; // COMPLIANT - type alias resolves to a compliant type + signed long x5 : 2; // NON_COMPLIANT - cannot declare bit field for long, even + // if it's signed + signed char x6 : 2; // NON_COMPLIANT - cannot declare bit field for char, even + // if it's signed + enum Color x7 : 3; // NON_COMPLIANT - cannot declare bit field for enum +} sample_struct; diff --git a/cpp/autosar/test/rules/M5-3-2/UnaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsigned.expected b/cpp/common/test/rules/builtinunaryoperatorappliedtounsignedexpression/BuiltInUnaryOperatorAppliedToUnsignedExpression.expected similarity index 100% rename from cpp/autosar/test/rules/M5-3-2/UnaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsigned.expected rename to cpp/common/test/rules/builtinunaryoperatorappliedtounsignedexpression/BuiltInUnaryOperatorAppliedToUnsignedExpression.expected diff --git a/cpp/common/test/rules/builtinunaryoperatorappliedtounsignedexpression/BuiltInUnaryOperatorAppliedToUnsignedExpression.ql b/cpp/common/test/rules/builtinunaryoperatorappliedtounsignedexpression/BuiltInUnaryOperatorAppliedToUnsignedExpression.ql new file mode 100644 index 0000000000..3f5110e299 --- /dev/null +++ b/cpp/common/test/rules/builtinunaryoperatorappliedtounsignedexpression/BuiltInUnaryOperatorAppliedToUnsignedExpression.ql @@ -0,0 +1,5 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.builtinunaryoperatorappliedtounsignedexpression.BuiltInUnaryOperatorAppliedToUnsignedExpression + +class TestFileQuery extends BuiltInUnaryOperatorAppliedToUnsignedExpressionSharedQuery, TestQuery { +} diff --git a/cpp/autosar/test/rules/M5-3-2/test.cpp b/cpp/common/test/rules/builtinunaryoperatorappliedtounsignedexpression/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M5-3-2/test.cpp rename to cpp/common/test/rules/builtinunaryoperatorappliedtounsignedexpression/test.cpp diff --git a/cpp/common/test/rules/castsbetweenapointertofunctionandanyothertype/CastsBetweenAPointerToFunctionAndAnyOtherType.expected b/cpp/common/test/rules/castsbetweenapointertofunctionandanyothertype/CastsBetweenAPointerToFunctionAndAnyOtherType.expected new file mode 100644 index 0000000000..24493879f0 --- /dev/null +++ b/cpp/common/test/rules/castsbetweenapointertofunctionandanyothertype/CastsBetweenAPointerToFunctionAndAnyOtherType.expected @@ -0,0 +1,2 @@ +| test.cpp:3:3:3:34 | reinterpret_cast<..(*)(..)>... | Cast converting a pointer to function. | +| test.cpp:4:3:4:30 | reinterpret_cast... | Cast converting a pointer to function. | diff --git a/cpp/common/test/rules/castsbetweenapointertofunctionandanyothertype/CastsBetweenAPointerToFunctionAndAnyOtherType.ql b/cpp/common/test/rules/castsbetweenapointertofunctionandanyothertype/CastsBetweenAPointerToFunctionAndAnyOtherType.ql new file mode 100644 index 0000000000..fd716b8570 --- /dev/null +++ b/cpp/common/test/rules/castsbetweenapointertofunctionandanyothertype/CastsBetweenAPointerToFunctionAndAnyOtherType.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.castsbetweenapointertofunctionandanyothertype.CastsBetweenAPointerToFunctionAndAnyOtherType + +class TestFileQuery extends CastsBetweenAPointerToFunctionAndAnyOtherTypeSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/M5-2-6/test.cpp b/cpp/common/test/rules/castsbetweenapointertofunctionandanyothertype/test.cpp similarity index 99% rename from cpp/autosar/test/rules/M5-2-6/test.cpp rename to cpp/common/test/rules/castsbetweenapointertofunctionandanyothertype/test.cpp index ac14351b00..aad03a054e 100644 --- a/cpp/autosar/test/rules/M5-2-6/test.cpp +++ b/cpp/common/test/rules/castsbetweenapointertofunctionandanyothertype/test.cpp @@ -1,3 +1,4 @@ + void f(int) { reinterpret_cast(&f); // NON_COMPLIANT reinterpret_cast(&f); // NON_COMPLIANT diff --git a/cpp/autosar/test/rules/M2-7-1/SlashStarUsedWithinACStyleComment.expected b/cpp/common/test/rules/charactersequenceusedwithinacstylecomment/CharacterSequenceUsedWithinACStyleComment.expected similarity index 100% rename from cpp/autosar/test/rules/M2-7-1/SlashStarUsedWithinACStyleComment.expected rename to cpp/common/test/rules/charactersequenceusedwithinacstylecomment/CharacterSequenceUsedWithinACStyleComment.expected diff --git a/cpp/common/test/rules/charactersequenceusedwithinacstylecomment/CharacterSequenceUsedWithinACStyleComment.ql b/cpp/common/test/rules/charactersequenceusedwithinacstylecomment/CharacterSequenceUsedWithinACStyleComment.ql new file mode 100644 index 0000000000..3fd1cf77ba --- /dev/null +++ b/cpp/common/test/rules/charactersequenceusedwithinacstylecomment/CharacterSequenceUsedWithinACStyleComment.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.charactersequenceusedwithinacstylecomment.CharacterSequenceUsedWithinACStyleComment + +class TestFileQuery extends CharacterSequenceUsedWithinACStyleCommentSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/M2-7-1/test.cpp b/cpp/common/test/rules/charactersequenceusedwithinacstylecomment/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M2-7-1/test.cpp rename to cpp/common/test/rules/charactersequenceusedwithinacstylecomment/test.cpp diff --git a/cpp/common/test/rules/constlikereturnvalue/ConstLikeReturnValue.expected b/cpp/common/test/rules/constlikereturnvalue/ConstLikeReturnValue.expected new file mode 100644 index 0000000000..b02aa464bb --- /dev/null +++ b/cpp/common/test/rules/constlikereturnvalue/ConstLikeReturnValue.expected @@ -0,0 +1,20 @@ +problems +| test.cpp:11:8:11:12 | c_str | test.cpp:18:16:18:21 | call to getenv | test.cpp:11:8:11:12 | c_str | The object returned by the function getenv should not be modified. | +| test.cpp:67:5:67:9 | conv4 | test.cpp:64:11:64:20 | call to localeconv | test.cpp:67:5:67:9 | conv4 | The object returned by the function localeconv should not be modified. | +| test.cpp:76:5:76:8 | conv | test.cpp:72:25:72:34 | call to localeconv | test.cpp:76:5:76:8 | conv | The object returned by the function localeconv should not be modified. | +edges +| test.cpp:8:18:8:22 | c_str | test.cpp:11:8:11:12 | c_str | +| test.cpp:18:16:18:21 | call to getenv | test.cpp:24:9:24:12 | env1 | +| test.cpp:24:9:24:12 | env1 | test.cpp:8:18:8:22 | c_str | +| test.cpp:64:11:64:20 | call to localeconv | test.cpp:67:5:67:9 | conv4 | +| test.cpp:72:25:72:34 | call to localeconv | test.cpp:76:5:76:8 | conv | +nodes +| test.cpp:8:18:8:22 | c_str | semmle.label | c_str | +| test.cpp:11:8:11:12 | c_str | semmle.label | c_str | +| test.cpp:18:16:18:21 | call to getenv | semmle.label | call to getenv | +| test.cpp:24:9:24:12 | env1 | semmle.label | env1 | +| test.cpp:64:11:64:20 | call to localeconv | semmle.label | call to localeconv | +| test.cpp:67:5:67:9 | conv4 | semmle.label | conv4 | +| test.cpp:72:25:72:34 | call to localeconv | semmle.label | call to localeconv | +| test.cpp:76:5:76:8 | conv | semmle.label | conv | +subpaths diff --git a/cpp/common/test/rules/constlikereturnvalue/ConstLikeReturnValue.ql b/cpp/common/test/rules/constlikereturnvalue/ConstLikeReturnValue.ql new file mode 100644 index 0000000000..53c27eb3ce --- /dev/null +++ b/cpp/common/test/rules/constlikereturnvalue/ConstLikeReturnValue.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.constlikereturnvalue.ConstLikeReturnValue + +class TestFileQuery extends ConstLikeReturnValueSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/constlikereturnvalue/test.cpp b/cpp/common/test/rules/constlikereturnvalue/test.cpp new file mode 100644 index 0000000000..19db17faee --- /dev/null +++ b/cpp/common/test/rules/constlikereturnvalue/test.cpp @@ -0,0 +1,96 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +#include +#include +#include +#include + +void trstr(char *c_str, char orig, char rep) { + while (*c_str != '\0') { + if (*c_str == orig) { + *c_str = rep; // NON_COMPLIANT + } + ++c_str; + } +} + +void f1(void) { + char *env1 = getenv("TEST_ENV"); + char *copy_of_env; + copy_of_env = env1; // COMPLIANT + + if (env1 == NULL) { + } + trstr(env1, '"', '_'); +} + +void f2(void) { + const char *env2; + char *copy_of_env; + + env2 = getenv("TEST_ENV"); + if (env2 == NULL) { + } + + copy_of_env = (char *)malloc(strlen(env2) + 1); + if (copy_of_env == NULL) { + } + + strcpy(copy_of_env, env2); + trstr(copy_of_env, '"', '_'); // COMPLIANT +} + +void f3(void) { + const char *env3; + char *copy_of_env; + + env3 = getenv("TEST_ENV"); + if (env3 == NULL) { + } + + copy_of_env = strdup(env3); + if (copy_of_env == NULL) { + } + + trstr(copy_of_env, '"', '_'); // COMPLIANT + if (setenv("TEST_ENV", copy_of_env, 1) != 0) { + } +} + +void f4(void) { + struct lconv *conv4 = localeconv(); + + setlocale(LC_ALL, "C"); // COMPLIANT + conv4 = localeconv(); // COMPLIANT + + if ('\0' == conv4->decimal_point[0]) { + conv4->decimal_point = "."; // NON_COMPLIANT + } +} + +void f4alias(void) { + struct lconv *conv4 = localeconv(); + struct lconv *conv = conv4; + + if ('\0' == conv4->decimal_point[0]) { + conv->decimal_point = "."; // NON_COMPLIANT + } +} + +void f5(void) { + const struct lconv *conv5 = localeconv(); + if (conv5 == NULL) { + } + + struct lconv *copy_of_conv = (struct lconv *)malloc(sizeof(struct lconv)); + if (copy_of_conv == NULL) { + } + + memcpy(copy_of_conv, conv5, sizeof(struct lconv)); + + if ('\0' == copy_of_conv->decimal_point[0]) { + copy_of_conv->decimal_point = "."; // COMPLIANT + } + + free(copy_of_conv); +} \ No newline at end of file diff --git a/cpp/autosar/test/rules/A12-8-5/CopyAssignmentAndAMoveHandleSelfAssignment.expected b/cpp/common/test/rules/copyandmoveassignmentsshallhandleselfassignment/CopyAndMoveAssignmentsShallHandleSelfAssignment.expected similarity index 100% rename from cpp/autosar/test/rules/A12-8-5/CopyAssignmentAndAMoveHandleSelfAssignment.expected rename to cpp/common/test/rules/copyandmoveassignmentsshallhandleselfassignment/CopyAndMoveAssignmentsShallHandleSelfAssignment.expected diff --git a/cpp/common/test/rules/copyandmoveassignmentsshallhandleselfassignment/CopyAndMoveAssignmentsShallHandleSelfAssignment.ql b/cpp/common/test/rules/copyandmoveassignmentsshallhandleselfassignment/CopyAndMoveAssignmentsShallHandleSelfAssignment.ql new file mode 100644 index 0000000000..9e84431f65 --- /dev/null +++ b/cpp/common/test/rules/copyandmoveassignmentsshallhandleselfassignment/CopyAndMoveAssignmentsShallHandleSelfAssignment.ql @@ -0,0 +1,5 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.copyandmoveassignmentsshallhandleselfassignment.CopyAndMoveAssignmentsShallHandleSelfAssignment + +class TestFileQuery extends CopyAndMoveAssignmentsShallHandleSelfAssignmentSharedQuery, TestQuery { +} diff --git a/cpp/autosar/test/rules/A12-8-5/test.cpp b/cpp/common/test/rules/copyandmoveassignmentsshallhandleselfassignment/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A12-8-5/test.cpp rename to cpp/common/test/rules/copyandmoveassignmentsshallhandleselfassignment/test.cpp diff --git a/cpp/autosar/test/rules/M18-7-1/CsignalFunctionsUsed.expected b/cpp/common/test/rules/csignalfunctionsused/CsignalFunctionsUsed.expected similarity index 100% rename from cpp/autosar/test/rules/M18-7-1/CsignalFunctionsUsed.expected rename to cpp/common/test/rules/csignalfunctionsused/CsignalFunctionsUsed.expected diff --git a/cpp/common/test/rules/csignalfunctionsused/CsignalFunctionsUsed.ql b/cpp/common/test/rules/csignalfunctionsused/CsignalFunctionsUsed.ql new file mode 100644 index 0000000000..1d39069ae7 --- /dev/null +++ b/cpp/common/test/rules/csignalfunctionsused/CsignalFunctionsUsed.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.csignalfunctionsused.CsignalFunctionsUsed + +class TestFileQuery extends CsignalFunctionsUsedSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/M18-7-1/test.cpp b/cpp/common/test/rules/csignalfunctionsused/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M18-7-1/test.cpp rename to cpp/common/test/rules/csignalfunctionsused/test.cpp diff --git a/cpp/autosar/test/rules/M18-7-1/CsignalTypesUsed.expected b/cpp/common/test/rules/csignaltypesused/CsignalTypesUsed.expected similarity index 100% rename from cpp/autosar/test/rules/M18-7-1/CsignalTypesUsed.expected rename to cpp/common/test/rules/csignaltypesused/CsignalTypesUsed.expected diff --git a/cpp/common/test/rules/csignaltypesused/CsignalTypesUsed.ql b/cpp/common/test/rules/csignaltypesused/CsignalTypesUsed.ql new file mode 100644 index 0000000000..76cc8aad04 --- /dev/null +++ b/cpp/common/test/rules/csignaltypesused/CsignalTypesUsed.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.csignaltypesused.CsignalTypesUsed + +class TestFileQuery extends CsignalTypesUsedSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/csignaltypesused/test.cpp b/cpp/common/test/rules/csignaltypesused/test.cpp new file mode 100644 index 0000000000..e621160b81 --- /dev/null +++ b/cpp/common/test/rules/csignaltypesused/test.cpp @@ -0,0 +1,13 @@ +#include + +void signal_handler(int signal) {} + +void test_signal_is_used() { + std::sig_atomic_t atom; // NON_COMPLIANT + std::signal(SIGINT, signal_handler); // NON_COMPLIANT + std::raise(SIGINT); // NON_COMPLIANT + + sig_atomic_t atom1; // NON_COMPLIANT + signal(SIGINT, signal_handler); // NON_COMPLIANT + raise(SIGINT); // NON_COMPLIANT +} \ No newline at end of file diff --git a/cpp/autosar/test/rules/M27-0-1/CstdioFunctionsUsed.expected b/cpp/common/test/rules/cstdiofunctionsused/CstdioFunctionsUsed.expected similarity index 100% rename from cpp/autosar/test/rules/M27-0-1/CstdioFunctionsUsed.expected rename to cpp/common/test/rules/cstdiofunctionsused/CstdioFunctionsUsed.expected diff --git a/cpp/common/test/rules/cstdiofunctionsused/CstdioFunctionsUsed.ql b/cpp/common/test/rules/cstdiofunctionsused/CstdioFunctionsUsed.ql new file mode 100644 index 0000000000..16dbb974b6 --- /dev/null +++ b/cpp/common/test/rules/cstdiofunctionsused/CstdioFunctionsUsed.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.cstdiofunctionsused.CstdioFunctionsUsed + +class TestFileQuery extends CstdioFunctionsUsedSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/M27-0-1/test.cpp b/cpp/common/test/rules/cstdiofunctionsused/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M27-0-1/test.cpp rename to cpp/common/test/rules/cstdiofunctionsused/test.cpp diff --git a/cpp/autosar/test/rules/M27-0-1/CstdioMacrosUsed.expected b/cpp/common/test/rules/cstdiomacrosused/CstdioMacrosUsed.expected similarity index 100% rename from cpp/autosar/test/rules/M27-0-1/CstdioMacrosUsed.expected rename to cpp/common/test/rules/cstdiomacrosused/CstdioMacrosUsed.expected diff --git a/cpp/common/test/rules/cstdiomacrosused/CstdioMacrosUsed.ql b/cpp/common/test/rules/cstdiomacrosused/CstdioMacrosUsed.ql new file mode 100644 index 0000000000..79ab6086b1 --- /dev/null +++ b/cpp/common/test/rules/cstdiomacrosused/CstdioMacrosUsed.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.cstdiomacrosused.CstdioMacrosUsed + +class TestFileQuery extends CstdioMacrosUsedSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/cstdiomacrosused/test.cpp b/cpp/common/test/rules/cstdiomacrosused/test.cpp new file mode 100644 index 0000000000..27447ba06a --- /dev/null +++ b/cpp/common/test/rules/cstdiomacrosused/test.cpp @@ -0,0 +1,61 @@ +#include +#include +void *test_cstdio_is_used() { + std::FILE *f = std::fopen("foo.txt", "r"); // NON_COMPLIANT + + std::fpos_t init_position; // NON_COMPLIANT + std::fgetpos(f, &init_position); // NON_COMPLIANT + + while (!std::feof(f)) { // NON_COMPLIANT + char c = std::fgetc(f); // NON_COMPLIANT + if (c == EOF) // NON_COMPLIANT + std::rewind(f); // NON_COMPLIANT + } + if (std::ferror(f)) { // NON_COMPLIANT + std::clearerr(f); // NON_COMPLIANT + std::fclose(f); // NON_COMPLIANT + std::perror("fgetc"); // NON_COMPLIANT + } + + std::fseek(f, (size_t)0, SEEK_SET); // NON_COMPLIANT + std::fseek(f, (size_t)0, SEEK_END); // NON_COMPLIANT + char buf[BUFSIZ]; // NON_COMPLIANT + std::fread(buf, 1, sizeof(buf), f); // NON_COMPLIANT + + std::fsetpos(f, &init_position); // NON_COMPLIANT + std::fflush(f); // NON_COMPLIANT + std::fclose(f); // NON_COMPLIANT + + std::printf("DEBUG: TMP_MAX=%d FILENAME_MAX=%d FOPEN_MAX=%d\n", TMP_MAX, + FILENAME_MAX, FOPEN_MAX); // NON_COMPLIANT + std::puts("all done!"); // NON_COMPLIANT + + // global namespace + FILE *f1 = fopen("foo.txt", "r"); // NON_COMPLIANT + + fpos_t init_position1; + fgetpos(f1, &init_position1); // NON_COMPLIANT + + while (!feof(f1)) { // NON_COMPLIANT + char c = fgetc(f1); // NON_COMPLIANT + if (c == EOF) // NON_COMPLIANT + rewind(f1); // NON_COMPLIANT + } + if (ferror(f1)) { // NON_COMPLIANT + clearerr(f1); // NON_COMPLIANT + fclose(f1); // NON_COMPLIANT + perror("fgetc"); // NON_COMPLIANT + } + + fseek(f1, (size_t)0, SEEK_SET); // NON_COMPLIANT + fread(buf, 1, sizeof(buf), f1); // NON_COMPLIANT + + fsetpos(f1, &init_position1); // NON_COMPLIANT + fflush(f1); // NON_COMPLIANT + fclose(f1); // NON_COMPLIANT + + printf("foo"); // NON_COMPLIANT + puts("all done!"); // NON_COMPLIANT + + return NULL; // COMPLIANT - NULL is not uniquely defined by cstdio +} \ No newline at end of file diff --git a/cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.expected b/cpp/common/test/rules/cstdiotypesused/CstdioTypesUsed.expected similarity index 100% rename from cpp/autosar/test/rules/M27-0-1/CstdioTypesUsed.expected rename to cpp/common/test/rules/cstdiotypesused/CstdioTypesUsed.expected diff --git a/cpp/common/test/rules/cstdiotypesused/CstdioTypesUsed.ql b/cpp/common/test/rules/cstdiotypesused/CstdioTypesUsed.ql new file mode 100644 index 0000000000..c5bac15c65 --- /dev/null +++ b/cpp/common/test/rules/cstdiotypesused/CstdioTypesUsed.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.cstdiotypesused.CstdioTypesUsed + +class TestFileQuery extends CstdioTypesUsedSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/cstdiotypesused/test.cpp b/cpp/common/test/rules/cstdiotypesused/test.cpp new file mode 100644 index 0000000000..27447ba06a --- /dev/null +++ b/cpp/common/test/rules/cstdiotypesused/test.cpp @@ -0,0 +1,61 @@ +#include +#include +void *test_cstdio_is_used() { + std::FILE *f = std::fopen("foo.txt", "r"); // NON_COMPLIANT + + std::fpos_t init_position; // NON_COMPLIANT + std::fgetpos(f, &init_position); // NON_COMPLIANT + + while (!std::feof(f)) { // NON_COMPLIANT + char c = std::fgetc(f); // NON_COMPLIANT + if (c == EOF) // NON_COMPLIANT + std::rewind(f); // NON_COMPLIANT + } + if (std::ferror(f)) { // NON_COMPLIANT + std::clearerr(f); // NON_COMPLIANT + std::fclose(f); // NON_COMPLIANT + std::perror("fgetc"); // NON_COMPLIANT + } + + std::fseek(f, (size_t)0, SEEK_SET); // NON_COMPLIANT + std::fseek(f, (size_t)0, SEEK_END); // NON_COMPLIANT + char buf[BUFSIZ]; // NON_COMPLIANT + std::fread(buf, 1, sizeof(buf), f); // NON_COMPLIANT + + std::fsetpos(f, &init_position); // NON_COMPLIANT + std::fflush(f); // NON_COMPLIANT + std::fclose(f); // NON_COMPLIANT + + std::printf("DEBUG: TMP_MAX=%d FILENAME_MAX=%d FOPEN_MAX=%d\n", TMP_MAX, + FILENAME_MAX, FOPEN_MAX); // NON_COMPLIANT + std::puts("all done!"); // NON_COMPLIANT + + // global namespace + FILE *f1 = fopen("foo.txt", "r"); // NON_COMPLIANT + + fpos_t init_position1; + fgetpos(f1, &init_position1); // NON_COMPLIANT + + while (!feof(f1)) { // NON_COMPLIANT + char c = fgetc(f1); // NON_COMPLIANT + if (c == EOF) // NON_COMPLIANT + rewind(f1); // NON_COMPLIANT + } + if (ferror(f1)) { // NON_COMPLIANT + clearerr(f1); // NON_COMPLIANT + fclose(f1); // NON_COMPLIANT + perror("fgetc"); // NON_COMPLIANT + } + + fseek(f1, (size_t)0, SEEK_SET); // NON_COMPLIANT + fread(buf, 1, sizeof(buf), f1); // NON_COMPLIANT + + fsetpos(f1, &init_position1); // NON_COMPLIANT + fflush(f1); // NON_COMPLIANT + fclose(f1); // NON_COMPLIANT + + printf("foo"); // NON_COMPLIANT + puts("all done!"); // NON_COMPLIANT + + return NULL; // COMPLIANT - NULL is not uniquely defined by cstdio +} \ No newline at end of file diff --git a/cpp/autosar/test/rules/A7-3-1/DefinitionNotConsideredForUnqualifiedLookup.expected b/cpp/common/test/rules/definitionnotconsideredforunqualifiedlookup/DefinitionNotConsideredForUnqualifiedLookup.expected similarity index 100% rename from cpp/autosar/test/rules/A7-3-1/DefinitionNotConsideredForUnqualifiedLookup.expected rename to cpp/common/test/rules/definitionnotconsideredforunqualifiedlookup/DefinitionNotConsideredForUnqualifiedLookup.expected diff --git a/cpp/common/test/rules/definitionnotconsideredforunqualifiedlookup/DefinitionNotConsideredForUnqualifiedLookup.ql b/cpp/common/test/rules/definitionnotconsideredforunqualifiedlookup/DefinitionNotConsideredForUnqualifiedLookup.ql new file mode 100644 index 0000000000..05457c997c --- /dev/null +++ b/cpp/common/test/rules/definitionnotconsideredforunqualifiedlookup/DefinitionNotConsideredForUnqualifiedLookup.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.definitionnotconsideredforunqualifiedlookup.DefinitionNotConsideredForUnqualifiedLookup + +class TestFileQuery extends DefinitionNotConsideredForUnqualifiedLookupSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/A7-3-1/test.cpp b/cpp/common/test/rules/definitionnotconsideredforunqualifiedlookup/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A7-3-1/test.cpp rename to cpp/common/test/rules/definitionnotconsideredforunqualifiedlookup/test.cpp diff --git a/cpp/autosar/test/rules/M15-1-3/EmptyThrowOutsideCatch.expected b/cpp/common/test/rules/emptythrowonlywithinacatchhandler/EmptyThrowOnlyWithinACatchHandler.expected similarity index 100% rename from cpp/autosar/test/rules/M15-1-3/EmptyThrowOutsideCatch.expected rename to cpp/common/test/rules/emptythrowonlywithinacatchhandler/EmptyThrowOnlyWithinACatchHandler.expected diff --git a/cpp/common/test/rules/emptythrowonlywithinacatchhandler/EmptyThrowOnlyWithinACatchHandler.ql b/cpp/common/test/rules/emptythrowonlywithinacatchhandler/EmptyThrowOnlyWithinACatchHandler.ql new file mode 100644 index 0000000000..a07b861639 --- /dev/null +++ b/cpp/common/test/rules/emptythrowonlywithinacatchhandler/EmptyThrowOnlyWithinACatchHandler.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.emptythrowonlywithinacatchhandler.EmptyThrowOnlyWithinACatchHandler + +class TestFileQuery extends EmptyThrowOnlyWithinACatchHandlerSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/M15-1-3/test.cpp b/cpp/common/test/rules/emptythrowonlywithinacatchhandler/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M15-1-3/test.cpp rename to cpp/common/test/rules/emptythrowonlywithinacatchhandler/test.cpp diff --git a/cpp/autosar/test/rules/A7-2-2/EnumerationUnderlyingBaseTypeNotExplicitlyDefined.expected b/cpp/common/test/rules/enumerationnotdefinedwithanexplicitunderlyingtype/EnumerationNotDefinedWithAnExplicitUnderlyingType.expected similarity index 100% rename from cpp/autosar/test/rules/A7-2-2/EnumerationUnderlyingBaseTypeNotExplicitlyDefined.expected rename to cpp/common/test/rules/enumerationnotdefinedwithanexplicitunderlyingtype/EnumerationNotDefinedWithAnExplicitUnderlyingType.expected diff --git a/cpp/common/test/rules/enumerationnotdefinedwithanexplicitunderlyingtype/EnumerationNotDefinedWithAnExplicitUnderlyingType.ql b/cpp/common/test/rules/enumerationnotdefinedwithanexplicitunderlyingtype/EnumerationNotDefinedWithAnExplicitUnderlyingType.ql new file mode 100644 index 0000000000..999f505c5f --- /dev/null +++ b/cpp/common/test/rules/enumerationnotdefinedwithanexplicitunderlyingtype/EnumerationNotDefinedWithAnExplicitUnderlyingType.ql @@ -0,0 +1,5 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.enumerationnotdefinedwithanexplicitunderlyingtype.EnumerationNotDefinedWithAnExplicitUnderlyingType + +class TestFileQuery extends EnumerationNotDefinedWithAnExplicitUnderlyingTypeSharedQuery, TestQuery { +} diff --git a/cpp/autosar/test/rules/A7-2-2/test.cpp b/cpp/common/test/rules/enumerationnotdefinedwithanexplicitunderlyingtype/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A7-2-2/test.cpp rename to cpp/common/test/rules/enumerationnotdefinedwithanexplicitunderlyingtype/test.cpp diff --git a/cpp/autosar/test/rules/A15-1-2/PointerExceptionObject.expected b/cpp/common/test/rules/exceptionobjecthavepointertype/ExceptionObjectHavePointerType.expected similarity index 100% rename from cpp/autosar/test/rules/A15-1-2/PointerExceptionObject.expected rename to cpp/common/test/rules/exceptionobjecthavepointertype/ExceptionObjectHavePointerType.expected diff --git a/cpp/common/test/rules/exceptionobjecthavepointertype/ExceptionObjectHavePointerType.ql b/cpp/common/test/rules/exceptionobjecthavepointertype/ExceptionObjectHavePointerType.ql new file mode 100644 index 0000000000..d0727790d3 --- /dev/null +++ b/cpp/common/test/rules/exceptionobjecthavepointertype/ExceptionObjectHavePointerType.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.exceptionobjecthavepointertype.ExceptionObjectHavePointerType + +class TestFileQuery extends ExceptionObjectHavePointerTypeSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/A15-1-2/test.cpp b/cpp/common/test/rules/exceptionobjecthavepointertype/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A15-1-2/test.cpp rename to cpp/common/test/rules/exceptionobjecthavepointertype/test.cpp diff --git a/cpp/autosar/test/rules/A18-9-2/ForwardingValuesToOtherFunctions.expected b/cpp/common/test/rules/forwardingreferencesandforwardnotusedtogether/ForwardingReferencesAndForwardNotUsedTogether.expected similarity index 100% rename from cpp/autosar/test/rules/A18-9-2/ForwardingValuesToOtherFunctions.expected rename to cpp/common/test/rules/forwardingreferencesandforwardnotusedtogether/ForwardingReferencesAndForwardNotUsedTogether.expected diff --git a/cpp/common/test/rules/forwardingreferencesandforwardnotusedtogether/ForwardingReferencesAndForwardNotUsedTogether.ql b/cpp/common/test/rules/forwardingreferencesandforwardnotusedtogether/ForwardingReferencesAndForwardNotUsedTogether.ql new file mode 100644 index 0000000000..4f08530f35 --- /dev/null +++ b/cpp/common/test/rules/forwardingreferencesandforwardnotusedtogether/ForwardingReferencesAndForwardNotUsedTogether.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.forwardingreferencesandforwardnotusedtogether.ForwardingReferencesAndForwardNotUsedTogether + +class TestFileQuery extends ForwardingReferencesAndForwardNotUsedTogetherSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/A18-9-2/test.cpp b/cpp/common/test/rules/forwardingreferencesandforwardnotusedtogether/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A18-9-2/test.cpp rename to cpp/common/test/rules/forwardingreferencesandforwardnotusedtogether/test.cpp diff --git a/cpp/common/test/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.expected b/cpp/common/test/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.expected new file mode 100644 index 0000000000..62787cca0b --- /dev/null +++ b/cpp/common/test/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.expected @@ -0,0 +1,2 @@ +| test.cpp:8:1:8:25 | #define MACRO4(x) (x + 1) | Macro used instead of a function. | +| test.cpp:13:1:13:48 | #define MACRO9() printf_custom("output = %d", 7) | Macro used instead of a function. | diff --git a/cpp/common/test/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.ql b/cpp/common/test/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.ql new file mode 100644 index 0000000000..29088c4458 --- /dev/null +++ b/cpp/common/test/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.functionlikemacrosdefined.FunctionLikeMacrosDefined + +class TestFileQuery extends FunctionLikeMacrosDefinedSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/functionlikemacrosdefined/test.cpp b/cpp/common/test/rules/functionlikemacrosdefined/test.cpp new file mode 100644 index 0000000000..f39236ca3b --- /dev/null +++ b/cpp/common/test/rules/functionlikemacrosdefined/test.cpp @@ -0,0 +1,42 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +#include + +#define MACRO(OP, L, R) ((L)OP(R)) // COMPLIANT +#define MACRO2(L, R) (L + R) // COMPLIANT +#define MACRO3(L, R) (L " " R " " L) // COMPLIANT +#define MACRO4(x) (x + 1) // NON_COMPLIANT +#define MACRO5(L, LR) (LR + 1) // COMPLIANT +#define MACRO6(x) printf_custom("output = %d", test##x) // COMPLIANT +#define MACRO7(x) #x // COMPLIANT +#define MACRO8(x) "NOP" // COMPLIANT +#define MACRO9() printf_custom("output = %d", 7) // NON_COMPLIANT +#define MACRO10(x) // COMPLIANT +#define MY_ASSERT(X) assert(X) // NON_COMPLIANT[FALSE_NEGATIVE] + +char a1[MACRO2(1, 1) + 6]; +extern int printf_custom(char *, int); +int test1; + +void f() { + int i = MACRO(+, 1, 1); + int i2 = MACRO2(7, 10); + + static int i3 = MACRO2(1, 1); + + char *i4 = MACRO3("prefix", "suffix"); + + int i5 = MACRO4(1); + + int i6 = MACRO4(MACRO2(1, 1)); + + int i7 = MACRO5(1, 1); + + MACRO6(1); + + char *i10 = MACRO7("prefix"); + + asm(MACRO8(1)); + + MY_ASSERT(1); +} \ No newline at end of file diff --git a/cpp/autosar/test/rules/A7-5-2/RecursiveFunctions.expected b/cpp/common/test/rules/functionscallthemselveseitherdirectlyorindirectly/FunctionsCallThemselvesEitherDirectlyOrIndirectly.expected similarity index 100% rename from cpp/autosar/test/rules/A7-5-2/RecursiveFunctions.expected rename to cpp/common/test/rules/functionscallthemselveseitherdirectlyorindirectly/FunctionsCallThemselvesEitherDirectlyOrIndirectly.expected diff --git a/cpp/common/test/rules/functionscallthemselveseitherdirectlyorindirectly/FunctionsCallThemselvesEitherDirectlyOrIndirectly.ql b/cpp/common/test/rules/functionscallthemselveseitherdirectlyorindirectly/FunctionsCallThemselvesEitherDirectlyOrIndirectly.ql new file mode 100644 index 0000000000..e95ba9b7f7 --- /dev/null +++ b/cpp/common/test/rules/functionscallthemselveseitherdirectlyorindirectly/FunctionsCallThemselvesEitherDirectlyOrIndirectly.ql @@ -0,0 +1,5 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.functionscallthemselveseitherdirectlyorindirectly.FunctionsCallThemselvesEitherDirectlyOrIndirectly + +class TestFileQuery extends FunctionsCallThemselvesEitherDirectlyOrIndirectlySharedQuery, TestQuery { +} diff --git a/cpp/autosar/test/rules/A7-5-2/test.cpp b/cpp/common/test/rules/functionscallthemselveseitherdirectlyorindirectly/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A7-5-2/test.cpp rename to cpp/common/test/rules/functionscallthemselveseitherdirectlyorindirectly/test.cpp diff --git a/cpp/autosar/test/rules/A14-8-2/ExplicitSpecializationsOfFunctionTemplatesUsed.expected b/cpp/common/test/rules/functiontemplatesexplicitlyspecialized/FunctionTemplatesExplicitlySpecialized.expected similarity index 100% rename from cpp/autosar/test/rules/A14-8-2/ExplicitSpecializationsOfFunctionTemplatesUsed.expected rename to cpp/common/test/rules/functiontemplatesexplicitlyspecialized/FunctionTemplatesExplicitlySpecialized.expected diff --git a/cpp/common/test/rules/functiontemplatesexplicitlyspecialized/FunctionTemplatesExplicitlySpecialized.ql b/cpp/common/test/rules/functiontemplatesexplicitlyspecialized/FunctionTemplatesExplicitlySpecialized.ql new file mode 100644 index 0000000000..a64a9786b6 --- /dev/null +++ b/cpp/common/test/rules/functiontemplatesexplicitlyspecialized/FunctionTemplatesExplicitlySpecialized.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.functiontemplatesexplicitlyspecialized.FunctionTemplatesExplicitlySpecialized + +class TestFileQuery extends FunctionTemplatesExplicitlySpecializedSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/A14-8-2/test.cpp b/cpp/common/test/rules/functiontemplatesexplicitlyspecialized/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A14-8-2/test.cpp rename to cpp/common/test/rules/functiontemplatesexplicitlyspecialized/test.cpp diff --git a/cpp/autosar/test/rules/M7-3-1/GlobalNamespaceMembershipViolation.expected b/cpp/common/test/rules/globalnamespacedeclarations/GlobalNamespaceDeclarations.expected similarity index 100% rename from cpp/autosar/test/rules/M7-3-1/GlobalNamespaceMembershipViolation.expected rename to cpp/common/test/rules/globalnamespacedeclarations/GlobalNamespaceDeclarations.expected diff --git a/cpp/common/test/rules/globalnamespacedeclarations/GlobalNamespaceDeclarations.ql b/cpp/common/test/rules/globalnamespacedeclarations/GlobalNamespaceDeclarations.ql new file mode 100644 index 0000000000..19482c5b09 --- /dev/null +++ b/cpp/common/test/rules/globalnamespacedeclarations/GlobalNamespaceDeclarations.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.globalnamespacedeclarations.GlobalNamespaceDeclarations + +class TestFileQuery extends GlobalNamespaceDeclarationsSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/M7-3-1/test.cpp b/cpp/common/test/rules/globalnamespacedeclarations/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M7-3-1/test.cpp rename to cpp/common/test/rules/globalnamespacedeclarations/test.cpp diff --git a/cpp/autosar/test/rules/A18-5-4/GlobalSizedOperatorDeleteNotDefined.expected b/cpp/common/test/rules/globalsizedoperatordeletenotdefined/GlobalSizedOperatorDeleteNotDefined.expected similarity index 100% rename from cpp/autosar/test/rules/A18-5-4/GlobalSizedOperatorDeleteNotDefined.expected rename to cpp/common/test/rules/globalsizedoperatordeletenotdefined/GlobalSizedOperatorDeleteNotDefined.expected diff --git a/cpp/common/test/rules/globalsizedoperatordeletenotdefined/GlobalSizedOperatorDeleteNotDefined.ql b/cpp/common/test/rules/globalsizedoperatordeletenotdefined/GlobalSizedOperatorDeleteNotDefined.ql new file mode 100644 index 0000000000..61d492f0c6 --- /dev/null +++ b/cpp/common/test/rules/globalsizedoperatordeletenotdefined/GlobalSizedOperatorDeleteNotDefined.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.globalsizedoperatordeletenotdefined.GlobalSizedOperatorDeleteNotDefined + +class TestFileQuery extends GlobalSizedOperatorDeleteNotDefinedSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/A18-5-4/test.cpp b/cpp/common/test/rules/globalsizedoperatordeletenotdefined/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A18-5-4/test.cpp rename to cpp/common/test/rules/globalsizedoperatordeletenotdefined/test.cpp diff --git a/cpp/autosar/test/rules/A18-5-4/GlobalUnsizedOperatorDeleteNotDefined.expected b/cpp/common/test/rules/globalunsizedoperatordeletenotdefined/GlobalUnsizedOperatorDeleteNotDefined.expected similarity index 100% rename from cpp/autosar/test/rules/A18-5-4/GlobalUnsizedOperatorDeleteNotDefined.expected rename to cpp/common/test/rules/globalunsizedoperatordeletenotdefined/GlobalUnsizedOperatorDeleteNotDefined.expected diff --git a/cpp/common/test/rules/globalunsizedoperatordeletenotdefined/GlobalUnsizedOperatorDeleteNotDefined.ql b/cpp/common/test/rules/globalunsizedoperatordeletenotdefined/GlobalUnsizedOperatorDeleteNotDefined.ql new file mode 100644 index 0000000000..c415cbcd70 --- /dev/null +++ b/cpp/common/test/rules/globalunsizedoperatordeletenotdefined/GlobalUnsizedOperatorDeleteNotDefined.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.globalunsizedoperatordeletenotdefined.GlobalUnsizedOperatorDeleteNotDefined + +class TestFileQuery extends GlobalUnsizedOperatorDeleteNotDefinedSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/globalunsizedoperatordeletenotdefined/test.cpp b/cpp/common/test/rules/globalunsizedoperatordeletenotdefined/test.cpp new file mode 100644 index 0000000000..8f77a41637 --- /dev/null +++ b/cpp/common/test/rules/globalunsizedoperatordeletenotdefined/test.cpp @@ -0,0 +1,3 @@ + +void operator delete(void *ptr) {} // NON_COMPLIANT +// void operator delete(void *ptr, std::size_t sz) {} diff --git a/cpp/common/test/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.expected b/cpp/common/test/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.expected new file mode 100644 index 0000000000..416f949eaa --- /dev/null +++ b/cpp/common/test/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.expected @@ -0,0 +1,2 @@ +| test.cpp:42:3:42:10 | goto ... | The goto statement and its $@ are not declared or enclosed in the same block. | test.cpp:46:3:46:5 | label ...: | label | +| test.cpp:57:5:57:12 | goto ... | The goto statement and its $@ are not declared or enclosed in the same block. | test.cpp:60:3:60:5 | label ...: | label | diff --git a/cpp/common/test/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.ql b/cpp/common/test/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.ql new file mode 100644 index 0000000000..f553135683 --- /dev/null +++ b/cpp/common/test/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.gotoreferencealabelinsurroundingblock.GotoReferenceALabelInSurroundingBlock + +class TestFileQuery extends GotoReferenceALabelInSurroundingBlockSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/gotoreferencealabelinsurroundingblock/test.cpp b/cpp/common/test/rules/gotoreferencealabelinsurroundingblock/test.cpp new file mode 100644 index 0000000000..07ebb4b13a --- /dev/null +++ b/cpp/common/test/rules/gotoreferencealabelinsurroundingblock/test.cpp @@ -0,0 +1,87 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +/*void f1() { + int i = 0; goto L1; + for (;i < 100; i++) { + L1: // NON_COMPLIANT - this is compiler checked + break; + } +}*/ + +void f2() { + int i = 0; + if (i >= 0) { + for (int j = 0; j < 10; j++) { + goto L2; + } + } +L2: // COMPLIANT + return; +} + +void f3() { + int i = 0; + if (i >= 0) { + for (int j = 0; j < 10; j++) { + goto L3; + L3: // COMPLIANT + break; + } + } +} + +void f4() { + int i = 0; +L4: // COMPLIANT + if (i >= 0) { + goto L4; + } +} + +void f5(int p) { + goto L1; + + switch (p) { + case 0: + L1:; // NON_COMPLIANT + break; + default: + break; + } +} + +void f6(int p) { + + switch (p) { + case 0: + goto L1; + break; + default: + L1: // NON_COMPLIANT + break; + } +} + +void f7(int p) { +L1: // COMPLIANT + switch (p) { + case 0: + goto L1; + break; + default: + break; + } +} + +void f8(int p) { + + switch (p) { + case 0: + goto L1; + ; + L1:; // COMPLIANT + break; + default: + break; + } +} diff --git a/cpp/common/test/rules/gotostatementcondition/GotoStatementCondition.expected b/cpp/common/test/rules/gotostatementcondition/GotoStatementCondition.expected index c1b2f35eda..9e9d81e62c 100644 --- a/cpp/common/test/rules/gotostatementcondition/GotoStatementCondition.expected +++ b/cpp/common/test/rules/gotostatementcondition/GotoStatementCondition.expected @@ -1,4 +1,4 @@ -| test.cpp:7:3:7:10 | goto ... | The $@ statement jumps to a $@ that is not declared later in the same function. | test.cpp:7:3:7:10 | goto ... | l1 | test.cpp:3:1:3:3 | label ...: | label ...: | -| test.cpp:19:3:19:10 | goto ... | The $@ statement jumps to a $@ that is not declared later in the same function. | test.cpp:19:3:19:10 | goto ... | l2 | test.cpp:15:1:15:3 | label ...: | label ...: | -| test.cpp:21:3:21:10 | goto ... | The $@ statement jumps to a $@ that is not declared later in the same function. | test.cpp:21:3:21:10 | goto ... | l1 | test.cpp:14:1:14:3 | label ...: | label ...: | -| test.cpp:26:3:26:10 | goto ... | The $@ statement jumps to a $@ that is not declared later in the same function. | test.cpp:26:3:26:10 | goto ... | l1 | test.cpp:25:1:25:3 | label ...: | label ...: | +| test.cpp:9:3:9:10 | goto ... | The $@ statement jumps to a $@ that is not declared later in the same function. | test.cpp:9:3:9:10 | goto ... | l1 | test.cpp:5:1:5:3 | label ...: | label ...: | +| test.cpp:21:3:21:10 | goto ... | The $@ statement jumps to a $@ that is not declared later in the same function. | test.cpp:21:3:21:10 | goto ... | l2 | test.cpp:17:1:17:3 | label ...: | label ...: | +| test.cpp:23:3:23:10 | goto ... | The $@ statement jumps to a $@ that is not declared later in the same function. | test.cpp:23:3:23:10 | goto ... | l1 | test.cpp:16:1:16:3 | label ...: | label ...: | +| test.cpp:28:3:28:10 | goto ... | The $@ statement jumps to a $@ that is not declared later in the same function. | test.cpp:28:3:28:10 | goto ... | l1 | test.cpp:27:1:27:3 | label ...: | label ...: | diff --git a/cpp/common/test/rules/gotostatementcondition/test.cpp b/cpp/common/test/rules/gotostatementcondition/test.cpp index 225c1b32f6..5854b21983 100644 --- a/cpp/common/test/rules/gotostatementcondition/test.cpp +++ b/cpp/common/test/rules/gotostatementcondition/test.cpp @@ -1,3 +1,5 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. void f1(int p1) { l1: diff --git a/cpp/common/test/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.expected b/cpp/common/test/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.expected new file mode 100644 index 0000000000..48547e3cca --- /dev/null +++ b/cpp/common/test/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.expected @@ -0,0 +1 @@ +| test.cpp:6:3:6:14 | goto ... | Use of goto. | diff --git a/cpp/common/test/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.ql b/cpp/common/test/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.ql new file mode 100644 index 0000000000..1a117d5ddd --- /dev/null +++ b/cpp/common/test/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.gotostatementshouldnotbeused.GotoStatementShouldNotBeUsed + +class TestFileQuery extends GotoStatementShouldNotBeUsedSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/gotostatementshouldnotbeused/test.cpp b/cpp/common/test/rules/gotostatementshouldnotbeused/test.cpp new file mode 100644 index 0000000000..0763208625 --- /dev/null +++ b/cpp/common/test/rules/gotostatementshouldnotbeused/test.cpp @@ -0,0 +1,11 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +void test_goto() { + int x = 1; + + goto label1; // NON_COMPLIANT + +label1: + + x = 2; +} \ No newline at end of file diff --git a/cpp/autosar/test/rules/A7-3-1/HiddenInheritedNonOverridableMemberFunction.expected b/cpp/common/test/rules/hiddeninheritednonoverridablememberfunction/HiddenInheritedNonOverridableMemberFunction.expected similarity index 100% rename from cpp/autosar/test/rules/A7-3-1/HiddenInheritedNonOverridableMemberFunction.expected rename to cpp/common/test/rules/hiddeninheritednonoverridablememberfunction/HiddenInheritedNonOverridableMemberFunction.expected diff --git a/cpp/common/test/rules/hiddeninheritednonoverridablememberfunction/HiddenInheritedNonOverridableMemberFunction.ql b/cpp/common/test/rules/hiddeninheritednonoverridablememberfunction/HiddenInheritedNonOverridableMemberFunction.ql new file mode 100644 index 0000000000..30953eacf3 --- /dev/null +++ b/cpp/common/test/rules/hiddeninheritednonoverridablememberfunction/HiddenInheritedNonOverridableMemberFunction.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.hiddeninheritednonoverridablememberfunction.HiddenInheritedNonOverridableMemberFunction + +class TestFileQuery extends HiddenInheritedNonOverridableMemberFunctionSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/hiddeninheritednonoverridablememberfunction/test.cpp b/cpp/common/test/rules/hiddeninheritednonoverridablememberfunction/test.cpp new file mode 100644 index 0000000000..c0904238c3 --- /dev/null +++ b/cpp/common/test/rules/hiddeninheritednonoverridablememberfunction/test.cpp @@ -0,0 +1,94 @@ +struct S1 { + int i; +}; + +class C1 { +public: + void f1(int); + + virtual void f2(int); + virtual void f2(double); + virtual void f2(S1); + +private: + void f3(int); + void f4(int); +}; + +class C2 : public C1 { +public: + void f1(double); // NON_COMPLIANT + + void f2(double) override; // NON_COMPLIANT +}; + +class C3 : public C1 { +public: + void f2(char *); // NON_COMPLIANT +}; + +class C4 : public C1 { +public: + using C1::f1; + void f1(double); // COMPLIANT + + using C1::f2; + void f2(double) override; // COMPLIANT +}; + +namespace ns1 { +void f1(int); +} + +using ns1::f1; + +namespace ns1 { +void f1(double); // NON_COMPLIANT +} + +void f1() { + C2 l1; + l1.f1(0); // calls C2::f1(double) instead of C1::f1(int) + l1.f2(0); // calls C2::f2(double) instead of C1::f2(int) + // S1 s1; + // l1.f2(s1); Won't compile because there is no suitable conversion from S1 to + // double. + C1 &l2{l1}; + l2.f1(0); // calls C1::f1(int) + + C4 l3; + l3.f1(0); // calls C1::f1(int) + l3.f1(0.0); // calls C3::f1(double) + l3.f2(0); // calls C1::f2(int) + l3.f2(0.0); // calls C3::f2(double) + S1 l4; + l3.f2(l4); // calls C1:f2(S1) +} + +class C5 : public C1 { +public: + void f1(double); // COMPLIANT + using C1::f1; // order of using and f1 declaration is not relevant + + void f2(double) override; // COMPLIANT + using C1::f2; // order of using and f2 declaration is not relevant +}; + +void f2() { + C5 c5; + c5.f1(0); // calls C1::f1(int) + c5.f1(0.0); // calls C5::f1(double) + c5.f2(0); // calls C1::f2(int) + c5.f2(0.0); // calls C5::f2(double) +} + +class C6 : public C1 { +public: + C6 &operator=(const C6 &); // COMPLIANT +}; + +class C7 : public C1 { + void f3(int); // COMPLIANT + + void f4(int); // COMPLIANT +}; \ No newline at end of file diff --git a/cpp/autosar/test/rules/A7-3-1/HiddenInheritedOverridableMemberFunction.expected b/cpp/common/test/rules/hiddeninheritedoverridablememberfunction/HiddenInheritedOverridableMemberFunction.expected similarity index 100% rename from cpp/autosar/test/rules/A7-3-1/HiddenInheritedOverridableMemberFunction.expected rename to cpp/common/test/rules/hiddeninheritedoverridablememberfunction/HiddenInheritedOverridableMemberFunction.expected diff --git a/cpp/common/test/rules/hiddeninheritedoverridablememberfunction/HiddenInheritedOverridableMemberFunction.ql b/cpp/common/test/rules/hiddeninheritedoverridablememberfunction/HiddenInheritedOverridableMemberFunction.ql new file mode 100644 index 0000000000..072f672efb --- /dev/null +++ b/cpp/common/test/rules/hiddeninheritedoverridablememberfunction/HiddenInheritedOverridableMemberFunction.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.hiddeninheritedoverridablememberfunction.HiddenInheritedOverridableMemberFunction + +class TestFileQuery extends HiddenInheritedOverridableMemberFunctionSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/hiddeninheritedoverridablememberfunction/test.cpp b/cpp/common/test/rules/hiddeninheritedoverridablememberfunction/test.cpp new file mode 100644 index 0000000000..c0904238c3 --- /dev/null +++ b/cpp/common/test/rules/hiddeninheritedoverridablememberfunction/test.cpp @@ -0,0 +1,94 @@ +struct S1 { + int i; +}; + +class C1 { +public: + void f1(int); + + virtual void f2(int); + virtual void f2(double); + virtual void f2(S1); + +private: + void f3(int); + void f4(int); +}; + +class C2 : public C1 { +public: + void f1(double); // NON_COMPLIANT + + void f2(double) override; // NON_COMPLIANT +}; + +class C3 : public C1 { +public: + void f2(char *); // NON_COMPLIANT +}; + +class C4 : public C1 { +public: + using C1::f1; + void f1(double); // COMPLIANT + + using C1::f2; + void f2(double) override; // COMPLIANT +}; + +namespace ns1 { +void f1(int); +} + +using ns1::f1; + +namespace ns1 { +void f1(double); // NON_COMPLIANT +} + +void f1() { + C2 l1; + l1.f1(0); // calls C2::f1(double) instead of C1::f1(int) + l1.f2(0); // calls C2::f2(double) instead of C1::f2(int) + // S1 s1; + // l1.f2(s1); Won't compile because there is no suitable conversion from S1 to + // double. + C1 &l2{l1}; + l2.f1(0); // calls C1::f1(int) + + C4 l3; + l3.f1(0); // calls C1::f1(int) + l3.f1(0.0); // calls C3::f1(double) + l3.f2(0); // calls C1::f2(int) + l3.f2(0.0); // calls C3::f2(double) + S1 l4; + l3.f2(l4); // calls C1:f2(S1) +} + +class C5 : public C1 { +public: + void f1(double); // COMPLIANT + using C1::f1; // order of using and f1 declaration is not relevant + + void f2(double) override; // COMPLIANT + using C1::f2; // order of using and f2 declaration is not relevant +}; + +void f2() { + C5 c5; + c5.f1(0); // calls C1::f1(int) + c5.f1(0.0); // calls C5::f1(double) + c5.f2(0); // calls C1::f2(int) + c5.f2(0.0); // calls C5::f2(double) +} + +class C6 : public C1 { +public: + C6 &operator=(const C6 &); // COMPLIANT +}; + +class C7 : public C1 { + void f3(int); // COMPLIANT + + void f4(int); // COMPLIANT +}; \ No newline at end of file diff --git a/cpp/autosar/test/rules/A12-1-1/ExplicitConstructorBaseClassInitialization.expected b/cpp/common/test/rules/initializeallvirtualbaseclasses/InitializeAllVirtualBaseClasses.expected similarity index 100% rename from cpp/autosar/test/rules/A12-1-1/ExplicitConstructorBaseClassInitialization.expected rename to cpp/common/test/rules/initializeallvirtualbaseclasses/InitializeAllVirtualBaseClasses.expected diff --git a/cpp/common/test/rules/initializeallvirtualbaseclasses/InitializeAllVirtualBaseClasses.ql b/cpp/common/test/rules/initializeallvirtualbaseclasses/InitializeAllVirtualBaseClasses.ql new file mode 100644 index 0000000000..89f720b125 --- /dev/null +++ b/cpp/common/test/rules/initializeallvirtualbaseclasses/InitializeAllVirtualBaseClasses.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.initializeallvirtualbaseclasses.InitializeAllVirtualBaseClasses + +class TestFileQuery extends InitializeAllVirtualBaseClassesSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/A12-1-1/test.cpp b/cpp/common/test/rules/initializeallvirtualbaseclasses/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A12-1-1/test.cpp rename to cpp/common/test/rules/initializeallvirtualbaseclasses/test.cpp diff --git a/cpp/autosar/test/rules/A8-5-4/ConfusingUseOfInitializerListConstructors.expected b/cpp/common/test/rules/initializerlistconstructoristheonlyconstructor/InitializerListConstructorIsTheOnlyConstructor.expected similarity index 100% rename from cpp/autosar/test/rules/A8-5-4/ConfusingUseOfInitializerListConstructors.expected rename to cpp/common/test/rules/initializerlistconstructoristheonlyconstructor/InitializerListConstructorIsTheOnlyConstructor.expected diff --git a/cpp/common/test/rules/initializerlistconstructoristheonlyconstructor/InitializerListConstructorIsTheOnlyConstructor.ql b/cpp/common/test/rules/initializerlistconstructoristheonlyconstructor/InitializerListConstructorIsTheOnlyConstructor.ql new file mode 100644 index 0000000000..a2b023a3dd --- /dev/null +++ b/cpp/common/test/rules/initializerlistconstructoristheonlyconstructor/InitializerListConstructorIsTheOnlyConstructor.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.initializerlistconstructoristheonlyconstructor.InitializerListConstructorIsTheOnlyConstructor + +class TestFileQuery extends InitializerListConstructorIsTheOnlyConstructorSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/A8-5-4/test.cpp b/cpp/common/test/rules/initializerlistconstructoristheonlyconstructor/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A8-5-4/test.cpp rename to cpp/common/test/rules/initializerlistconstructoristheonlyconstructor/test.cpp diff --git a/cpp/common/test/rules/invalidatedenvstringpointers/InvalidatedEnvStringPointers.expected b/cpp/common/test/rules/invalidatedenvstringpointers/InvalidatedEnvStringPointers.expected new file mode 100644 index 0000000000..9a39d3a88d --- /dev/null +++ b/cpp/common/test/rules/invalidatedenvstringpointers/InvalidatedEnvStringPointers.expected @@ -0,0 +1,6 @@ +| test.cpp:21:14:21:19 | tmpvar | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.cpp:13:12:13:17 | call to getenv | call to getenv | test.cpp:17:13:17:18 | call to getenv | call to getenv | +| test.cpp:134:14:134:17 | temp | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.cpp:130:12:130:17 | call to getenv | call to getenv | test.cpp:131:11:131:16 | call to getenv | call to getenv | +| test.cpp:134:20:134:22 | tmp | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.cpp:131:11:131:16 | call to getenv | call to getenv | test.cpp:130:12:130:17 | call to getenv | call to getenv | +| test.cpp:165:14:165:26 | tmpvar_global | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.cpp:157:19:157:24 | call to getenv | call to getenv | test.cpp:161:20:161:25 | call to getenv | call to getenv | +| test.cpp:188:18:188:18 | r | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.cpp:185:7:185:15 | call to setlocale | call to setlocale | test.cpp:187:8:187:17 | call to localeconv | call to localeconv | +| test.cpp:208:10:208:15 | tmpvar | This pointer was returned by a $@ and may have been overwritten by the susequent $@. | test.cpp:202:12:202:17 | call to getenv | call to getenv | test.cpp:206:3:206:8 | call to f11fun | call to f11fun | diff --git a/cpp/common/test/rules/invalidatedenvstringpointers/InvalidatedEnvStringPointers.ql b/cpp/common/test/rules/invalidatedenvstringpointers/InvalidatedEnvStringPointers.ql new file mode 100644 index 0000000000..b82c43333a --- /dev/null +++ b/cpp/common/test/rules/invalidatedenvstringpointers/InvalidatedEnvStringPointers.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.invalidatedenvstringpointers.InvalidatedEnvStringPointers + +class TestFileQuery extends InvalidatedEnvStringPointersSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/invalidatedenvstringpointers/test.cpp b/cpp/common/test/rules/invalidatedenvstringpointers/test.cpp new file mode 100644 index 0000000000..74e3d1b8f5 --- /dev/null +++ b/cpp/common/test/rules/invalidatedenvstringpointers/test.cpp @@ -0,0 +1,209 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +#include +#include +#include +#include +#include + +void f1(void) { + char *tmpvar; + char *tempvar; + + tmpvar = getenv("TMP"); + if (!tmpvar) { + /* Handle error */ + } + tempvar = getenv("TEMP"); + if (!tempvar) { + /* Handle error */ + } + if (strcmp(tmpvar, tempvar) == 0) { // NON_COMPLIANT + printf("TMP and TEMP are the same.\n"); + } else { + printf("TMP and TEMP are NOT the same.\n"); + } +} + +void f2(void) { + char *tmpvar; + char *tempvar; + + const char *temp = getenv("TMP"); + if (temp != NULL) { + tmpvar = (char *)malloc(strlen(temp) + 1); + if (tmpvar != NULL) { + strcpy(tmpvar, temp); + } else { + /* Handle error */ + } + } else { + /* Handle error */ + } + + temp = getenv("TEMP"); + if (temp != NULL) { + tempvar = (char *)malloc(strlen(temp) + 1); + if (tempvar != NULL) { + strcpy(tempvar, temp); + } else { + /* Handle error */ + } + } else { + /* Handle error */ + } + + if (strcmp(tmpvar, tempvar) == 0) { // COMPLIANT + printf("TMP and TEMP are the same.\n"); + } else { + printf("TMP and TEMP are NOT the same.\n"); + } + free(tmpvar); + free(tempvar); +} + +#define __STDC_WANT_LIB_EXT1__ 1 + +void f3(void) { + char *tmpvar; + char *tempvar; + + const char *temp = getenv("TMP"); + if (temp != NULL) { + tmpvar = strdup(temp); + if (tmpvar == NULL) { + /* Handle error */ + } + } else { + /* Handle error */ + } + + temp = getenv("TEMP"); + if (temp != NULL) { + tempvar = strdup(temp); + if (tempvar == NULL) { + /* Handle error */ + } + } else { + /* Handle error */ + } + + if (strcmp(tmpvar, tempvar) == 0) { // COMPLIANT + printf("TMP and TEMP are the same.\n"); + } else { + printf("TMP and TEMP are NOT the same.\n"); + } + free(tmpvar); + tmpvar = NULL; + free(tempvar); + tempvar = NULL; +} + +void f4(void) { + char *temp = getenv("VAR1"); + printf(temp); + temp = getenv("VAR2"); + printf(temp); // COMPLIANT +} + +void f5(void) { + const char *envVars[] = { + "v1", + "v2", + "v3", + }; + for (int i = 0; i < 3; i++) { + char *temp = getenv(envVars[i]); + printf(temp); // COMPLIANT + } +} + +void f5b(void) { + const char *envVars[] = { + "v1", + "v2", + "v3", + }; + char *temp; + char *tmp; + for (int i = 0; i < 3; i++) { + temp = getenv(envVars[i]); + tmp = getenv(envVars[i]); + } + + if (strcmp(temp, tmp) == 0) { // NON_COMPLIANT + printf("TMP and TEMP are the same.\n"); + } else { + printf("TMP and TEMP are NOT the same.\n"); + } +} + +void f6(void) { + const char *envVars[] = { + "v1", + "v2", + "v3", + }; + char *temp[3]; + for (int i = 0; i < 3; i++) { + temp[i] = getenv(envVars[i]); + } + printf(temp[0]); // NON_COMPLIANT[FALSE_NEGATIVE] +} + +char *tmpvar_global; +char *tempvar_global; +void f7(void) { + tmpvar_global = getenv("TMP"); + if (!tmpvar_global) { + /* Handle error */ + } + tempvar_global = getenv("TEMP"); + if (!tempvar_global) { + /* Handle error */ + } + if (strcmp(tmpvar_global, tempvar_global) == 0) { // NON_COMPLIANT + printf("TMP and TEMP are the same.\n"); + } else { + printf("TMP and TEMP are NOT the same.\n"); + } +} + +extern void f8fun(); +void f8(void) { + char *temp = getenv("VAR1"); + printf(temp); + f8fun(); // this function might call getenv() + temp = getenv("VAR2"); + printf(temp); // NON_COMPLIANT[FALSE_NEGATIVE] +} + +void f9(void) { + const char *r; + struct lconv *lc; + char c[128]; + r = setlocale(LC_ALL, "ja_JP.UTF-8"); + strcpy(c, r); + lc = localeconv(); + printf("%s\n", r); // NON_COMPLIANT + printf("%s\n", c); // COMPLIANT + printf("%s\n", lc->currency_symbol); // COMPLIANT +} + +void f10(void) { + struct tm tm = *localtime(&(time_t){time(NULL)}); + printf("%s", asctime(&tm)); // COMPLIANT +} + +void f11fun(void) { char *tempvar = getenv("TEMP"); } +void f11(void) { + char *tmpvar; + + tmpvar = getenv("TMP"); + if (!tmpvar) { + /* Handle error */ + } + f11fun(); + + printf(tmpvar); // NON_COMPLIANT +} diff --git a/cpp/common/test/rules/invalidatedenvstringpointerswarn/InvalidatedEnvStringPointersWarn.expected b/cpp/common/test/rules/invalidatedenvstringpointerswarn/InvalidatedEnvStringPointersWarn.expected new file mode 100644 index 0000000000..9061fcfbc4 --- /dev/null +++ b/cpp/common/test/rules/invalidatedenvstringpointerswarn/InvalidatedEnvStringPointersWarn.expected @@ -0,0 +1,2 @@ +| test.cpp:15:19:15:24 | call to getenv | The value of variable $@ might become invalid after a subsequent call to function `getenv`. | test.cpp:12:7:12:19 | tmpvar_global | tmpvar_global | +| test.cpp:18:20:18:25 | call to getenv | The value of variable $@ might become invalid after a subsequent call to function `getenv`. | test.cpp:9:9:9:20 | tmpvar_field | tmpvar_field | diff --git a/cpp/common/test/rules/invalidatedenvstringpointerswarn/InvalidatedEnvStringPointersWarn.ql b/cpp/common/test/rules/invalidatedenvstringpointerswarn/InvalidatedEnvStringPointersWarn.ql new file mode 100644 index 0000000000..7a56af210d --- /dev/null +++ b/cpp/common/test/rules/invalidatedenvstringpointerswarn/InvalidatedEnvStringPointersWarn.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.invalidatedenvstringpointerswarn.InvalidatedEnvStringPointersWarn + +class TestFileQuery extends InvalidatedEnvStringPointersWarnSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/invalidatedenvstringpointerswarn/test.cpp b/cpp/common/test/rules/invalidatedenvstringpointerswarn/test.cpp new file mode 100644 index 0000000000..5001e538a1 --- /dev/null +++ b/cpp/common/test/rules/invalidatedenvstringpointerswarn/test.cpp @@ -0,0 +1,21 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +#include +#include +#include +#include + +struct test_struct { + char *tmpvar_field; +}; + +char *tmpvar_global; + +void f1(void) { + tmpvar_global = getenv("TMP"); // NON_COMPLIANT + + struct test_struct s; + s.tmpvar_field = getenv("TEMP"); // NON_COMPLIANT + + char *tmpvar_local = getenv("TEMP"); // COMPLIANT +} diff --git a/cpp/autosar/test/rules/A2-7-1/SingleLineCommentEndsWithSlash.expected b/cpp/common/test/rules/linesplicingusedincomments/LineSplicingUsedInComments.expected similarity index 100% rename from cpp/autosar/test/rules/A2-7-1/SingleLineCommentEndsWithSlash.expected rename to cpp/common/test/rules/linesplicingusedincomments/LineSplicingUsedInComments.expected diff --git a/cpp/common/test/rules/linesplicingusedincomments/LineSplicingUsedInComments.ql b/cpp/common/test/rules/linesplicingusedincomments/LineSplicingUsedInComments.ql new file mode 100644 index 0000000000..55803eab88 --- /dev/null +++ b/cpp/common/test/rules/linesplicingusedincomments/LineSplicingUsedInComments.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.linesplicingusedincomments.LineSplicingUsedInComments + +class TestFileQuery extends LineSplicingUsedInCommentsSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/A2-7-1/test.cpp b/cpp/common/test/rules/linesplicingusedincomments/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A2-7-1/test.cpp rename to cpp/common/test/rules/linesplicingusedincomments/test.cpp diff --git a/cpp/autosar/test/rules/M6-3-1/LoopCompoundCondition.expected b/cpp/common/test/rules/loopcompoundcondition/LoopCompoundCondition.expected similarity index 100% rename from cpp/autosar/test/rules/M6-3-1/LoopCompoundCondition.expected rename to cpp/common/test/rules/loopcompoundcondition/LoopCompoundCondition.expected diff --git a/cpp/common/test/rules/loopcompoundcondition/LoopCompoundCondition.ql b/cpp/common/test/rules/loopcompoundcondition/LoopCompoundCondition.ql new file mode 100644 index 0000000000..3961d76d15 --- /dev/null +++ b/cpp/common/test/rules/loopcompoundcondition/LoopCompoundCondition.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.loopcompoundcondition.LoopCompoundCondition + +class TestFileQuery extends LoopCompoundConditionSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/M6-3-1/test.cpp b/cpp/common/test/rules/loopcompoundcondition/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M6-3-1/test.cpp rename to cpp/common/test/rules/loopcompoundcondition/test.cpp diff --git a/cpp/common/test/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.expected b/cpp/common/test/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.expected new file mode 100644 index 0000000000..545b6d3441 --- /dev/null +++ b/cpp/common/test/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.expected @@ -0,0 +1,16 @@ +| test.cpp:5:10:5:11 | 0 | Lowercase 'l' used as a literal suffix. | +| test.cpp:6:10:6:12 | 0 | Lowercase 'l' used as a literal suffix. | +| test.cpp:9:10:9:12 | 0 | Lowercase 'l' used as a literal suffix. | +| test.cpp:10:10:10:12 | 0 | Lowercase 'l' used as a literal suffix. | +| test.cpp:15:11:15:12 | 0 | Lowercase 'l' used as a literal suffix. | +| test.cpp:16:11:16:13 | 0 | Lowercase 'l' used as a literal suffix. | +| test.cpp:19:11:19:13 | 0 | Lowercase 'l' used as a literal suffix. | +| test.cpp:20:11:20:13 | 0 | Lowercase 'l' used as a literal suffix. | +| test.cpp:25:10:25:14 | 1 | Lowercase 'l' used as a literal suffix. | +| test.cpp:26:10:26:15 | 1 | Lowercase 'l' used as a literal suffix. | +| test.cpp:29:10:29:15 | 1 | Lowercase 'l' used as a literal suffix. | +| test.cpp:30:10:30:15 | 1 | Lowercase 'l' used as a literal suffix. | +| test.cpp:35:11:35:14 | 1 | Lowercase 'l' used as a literal suffix. | +| test.cpp:36:11:36:15 | 1 | Lowercase 'l' used as a literal suffix. | +| test.cpp:39:11:39:15 | 1 | Lowercase 'l' used as a literal suffix. | +| test.cpp:40:11:40:15 | 1 | Lowercase 'l' used as a literal suffix. | diff --git a/cpp/common/test/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.ql b/cpp/common/test/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.ql new file mode 100644 index 0000000000..ab353ca8a9 --- /dev/null +++ b/cpp/common/test/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.lowercaselstartsinliteralsuffix.LowercaseLStartsInLiteralSuffix + +class TestFileQuery extends LowercaseLStartsInLiteralSuffixSharedQuery, TestQuery { } diff --git a/c/misra/test/rules/RULE-7-3/cpp/README.md b/cpp/common/test/rules/lowercaselstartsinliteralsuffix/README.md similarity index 100% rename from c/misra/test/rules/RULE-7-3/cpp/README.md rename to cpp/common/test/rules/lowercaselstartsinliteralsuffix/README.md diff --git a/cpp/common/test/rules/lowercaselstartsinliteralsuffix/test.cpp b/cpp/common/test/rules/lowercaselstartsinliteralsuffix/test.cpp new file mode 100644 index 0000000000..27be2a327d --- /dev/null +++ b/cpp/common/test/rules/lowercaselstartsinliteralsuffix/test.cpp @@ -0,0 +1,46 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +int x = false; // COMPLIANT - reported as FP in #319 +int a1 = 0L; // COMPLIANT +int a2 = 0l; // NON_COMPLIANT +int a3 = 0ll; // NON_COMPLIANT +int a4 = 0LL; // COMPLIANT +int a5 = 0uL; // COMPLIANT +int a6 = 0ul; // NON_COMPLIANT +int a7 = 0lu; // NON_COMPLIANT +int a8 = 0Lu; // COMPLIANT +int a9 = 0LU; // COMPLIANT + +long b1 = 0L; // COMPLIANT +long b2 = 0l; // NON_COMPLIANT +long b3 = 0ll; // NON_COMPLIANT +long b4 = 0LL; // COMPLIANT +long b5 = 0uL; // COMPLIANT +long b6 = 0ul; // NON_COMPLIANT +long b7 = 0lu; // NON_COMPLIANT +long b8 = 0Lu; // COMPLIANT +long b9 = 0LU; // COMPLIANT + +int c1 = 0x01L; // COMPLIANT +int c2 = 0x01l; // NON_COMPLIANT +int c3 = 0x01ll; // NON_COMPLIANT +int c4 = 0x01LL; // COMPLIANT +int c5 = 0x01uL; // COMPLIANT +int c6 = 0x01ul; // NON_COMPLIANT +int c7 = 0x01lu; // NON_COMPLIANT +int c8 = 0x01Lu; // COMPLIANT +int c9 = 0x01LU; // COMPLIANT + +long d1 = 001L; // COMPLIANT +long d2 = 001l; // NON_COMPLIANT +long d3 = 001ll; // NON_COMPLIANT +long d4 = 001LL; // COMPLIANT +long d5 = 001uL; // COMPLIANT +long d6 = 001ul; // NON_COMPLIANT +long d7 = 001lu; // NON_COMPLIANT +long d8 = 001Lu; // COMPLIANT +long d9 = 001LU; // COMPLIANT + +char *e1 = ""; +char *e2 = "ul"; +char *e3 = "UL"; \ No newline at end of file diff --git a/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.expected b/cpp/common/test/rules/macrooffsetofused/MacroOffsetofUsed.expected similarity index 100% rename from cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.expected rename to cpp/common/test/rules/macrooffsetofused/MacroOffsetofUsed.expected diff --git a/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.expected.gcc b/cpp/common/test/rules/macrooffsetofused/MacroOffsetofUsed.expected.gcc similarity index 100% rename from cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.expected.gcc rename to cpp/common/test/rules/macrooffsetofused/MacroOffsetofUsed.expected.gcc diff --git a/cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.expected.qcc b/cpp/common/test/rules/macrooffsetofused/MacroOffsetofUsed.expected.qcc similarity index 100% rename from cpp/autosar/test/rules/M18-2-1/MacroOffsetofUsed.expected.qcc rename to cpp/common/test/rules/macrooffsetofused/MacroOffsetofUsed.expected.qcc diff --git a/cpp/common/test/rules/macrooffsetofused/MacroOffsetofUsed.ql b/cpp/common/test/rules/macrooffsetofused/MacroOffsetofUsed.ql new file mode 100644 index 0000000000..44e30b1a2f --- /dev/null +++ b/cpp/common/test/rules/macrooffsetofused/MacroOffsetofUsed.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.macrooffsetofused.MacroOffsetofUsed + +class TestFileQuery extends MacroOffsetofUsedSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/M18-2-1/test.cpp b/cpp/common/test/rules/macrooffsetofused/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M18-2-1/test.cpp rename to cpp/common/test/rules/macrooffsetofused/test.cpp diff --git a/cpp/common/test/rules/macroparameterfollowinghash/MacroParameterFollowingHash.expected b/cpp/common/test/rules/macroparameterfollowinghash/MacroParameterFollowingHash.expected new file mode 100644 index 0000000000..6a3d5c5da7 --- /dev/null +++ b/cpp/common/test/rules/macroparameterfollowinghash/MacroParameterFollowingHash.expected @@ -0,0 +1 @@ +| test.cpp:27:1:27:29 | #define MACROTHIRTEEN(X) #X ## X | Macro definition uses an # operator followed by a ## operator. | diff --git a/cpp/common/test/rules/macroparameterfollowinghash/MacroParameterFollowingHash.ql b/cpp/common/test/rules/macroparameterfollowinghash/MacroParameterFollowingHash.ql new file mode 100644 index 0000000000..f753b75463 --- /dev/null +++ b/cpp/common/test/rules/macroparameterfollowinghash/MacroParameterFollowingHash.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.macroparameterfollowinghash.MacroParameterFollowingHash + +class TestFileQuery extends MacroParameterFollowingHashSharedQuery, TestQuery { } diff --git a/c/misra/test/rules/RULE-20-11/test.c b/cpp/common/test/rules/macroparameterfollowinghash/test.cpp similarity index 83% rename from c/misra/test/rules/RULE-20-11/test.c rename to cpp/common/test/rules/macroparameterfollowinghash/test.cpp index ad2c205970..5e6f187445 100644 --- a/c/misra/test/rules/RULE-20-11/test.c +++ b/cpp/common/test/rules/macroparameterfollowinghash/test.cpp @@ -1,3 +1,5 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. #define MACROONE 1 // COMPLIANT #define MACROTWO '#\'-#' + '#' // COMPLIANT diff --git a/cpp/autosar/test/rules/M8-0-1/MultipleGlobalOrMemberDeclarators.expected b/cpp/common/test/rules/multipleglobalormemberdeclarators/MultipleGlobalOrMemberDeclarators.expected similarity index 100% rename from cpp/autosar/test/rules/M8-0-1/MultipleGlobalOrMemberDeclarators.expected rename to cpp/common/test/rules/multipleglobalormemberdeclarators/MultipleGlobalOrMemberDeclarators.expected diff --git a/cpp/common/test/rules/multipleglobalormemberdeclarators/MultipleGlobalOrMemberDeclarators.ql b/cpp/common/test/rules/multipleglobalormemberdeclarators/MultipleGlobalOrMemberDeclarators.ql new file mode 100644 index 0000000000..2f4d3cbdea --- /dev/null +++ b/cpp/common/test/rules/multipleglobalormemberdeclarators/MultipleGlobalOrMemberDeclarators.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.multipleglobalormemberdeclarators.MultipleGlobalOrMemberDeclarators + +class TestFileQuery extends MultipleGlobalOrMemberDeclaratorsSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/M8-0-1/test.cpp b/cpp/common/test/rules/multipleglobalormemberdeclarators/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M8-0-1/test.cpp rename to cpp/common/test/rules/multipleglobalormemberdeclarators/test.cpp diff --git a/cpp/autosar/test/rules/M8-0-1/MultipleLocalDeclarators.expected b/cpp/common/test/rules/multiplelocaldeclarators/MultipleLocalDeclarators.expected similarity index 100% rename from cpp/autosar/test/rules/M8-0-1/MultipleLocalDeclarators.expected rename to cpp/common/test/rules/multiplelocaldeclarators/MultipleLocalDeclarators.expected diff --git a/cpp/common/test/rules/multiplelocaldeclarators/MultipleLocalDeclarators.ql b/cpp/common/test/rules/multiplelocaldeclarators/MultipleLocalDeclarators.ql new file mode 100644 index 0000000000..7e2fe57b24 --- /dev/null +++ b/cpp/common/test/rules/multiplelocaldeclarators/MultipleLocalDeclarators.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.multiplelocaldeclarators.MultipleLocalDeclarators + +class TestFileQuery extends MultipleLocalDeclaratorsSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/multiplelocaldeclarators/test.cpp b/cpp/common/test/rules/multiplelocaldeclarators/test.cpp new file mode 100644 index 0000000000..cf664e4b34 --- /dev/null +++ b/cpp/common/test/rules/multiplelocaldeclarators/test.cpp @@ -0,0 +1,24 @@ +int g1, g2; // NON_COMPLIANT +int g3; // COMPLIANT + +namespace n1 { +int n_v1, n_v2; // NON_COMPLIANT +int n_v3; // COMPLIANT +} // namespace n1 + +void f() { + int l1, l2; // NON_COMPLIANT + int l3; // COMPLIANT +} + +class ClassA { + int m1, m2; // NON_COMPLIANT + int m3; // COMPLIANT +}; + +#include +void test_loop(std::vector v) { + for (const auto b : v) { // COMPLIANT - DeclStmt is compiler generated + b; + } +} \ No newline at end of file diff --git a/cpp/common/test/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.expected b/cpp/common/test/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.expected new file mode 100644 index 0000000000..8ddc10e90c --- /dev/null +++ b/cpp/common/test/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.expected @@ -0,0 +1,5 @@ +| test.cpp:6:7:6:8 | x1 | A named bit-field with signed integral type should have at least 2 bits of storage. | +| test.cpp:9:14:9:15 | x2 | A named bit-field with signed integral type should have at least 2 bits of storage. | +| test.cpp:11:7:11:8 | x3 | A named bit-field with signed integral type should have at least 2 bits of storage. | +| test.cpp:13:7:13:8 | x4 | A named bit-field with signed integral type should have at least 2 bits of storage. | +| test.cpp:22:14:22:14 | x | A named bit-field with signed integral type should have at least 2 bits of storage. | diff --git a/cpp/common/test/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.ql b/cpp/common/test/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.ql new file mode 100644 index 0000000000..a82fa7905a --- /dev/null +++ b/cpp/common/test/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.namedbitfieldswithsignedintegertype.NamedBitFieldsWithSignedIntegerType + +class TestFileQuery extends NamedBitFieldsWithSignedIntegerTypeSharedQuery, TestQuery { } diff --git a/c/misra/test/rules/RULE-6-2/test.c b/cpp/common/test/rules/namedbitfieldswithsignedintegertype/test.cpp similarity index 70% rename from c/misra/test/rules/RULE-6-2/test.c rename to cpp/common/test/rules/namedbitfieldswithsignedintegertype/test.cpp index 8182dfdb5d..0d6e838f83 100644 --- a/c/misra/test/rules/RULE-6-2/test.c +++ b/cpp/common/test/rules/namedbitfieldswithsignedintegertype/test.cpp @@ -1,3 +1,5 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. #include struct SampleStruct { @@ -15,3 +17,12 @@ struct SampleStruct { // to carry more than 1 bit signed char : 1; // COMPLIANT: single-bit bit-field but unnamed } sample_struct; + +struct S { + signed int x : 1; // NON-COMPLIANT + signed int y : 5; // COMPLIANT + signed int z : 7; // COMPLIANT + signed int : 0; // COMPLIANT + signed int : 1; // COMPLIANT + signed int : 2; // COMPLIANT +}; \ No newline at end of file diff --git a/cpp/autosar/test/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThis.expected b/cpp/common/test/rules/namenotreferredusingaqualifiedidorthis/NameNotReferredUsingAQualifiedIdOrThis.expected similarity index 100% rename from cpp/autosar/test/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThis.expected rename to cpp/common/test/rules/namenotreferredusingaqualifiedidorthis/NameNotReferredUsingAQualifiedIdOrThis.expected diff --git a/cpp/common/test/rules/namenotreferredusingaqualifiedidorthis/NameNotReferredUsingAQualifiedIdOrThis.ql b/cpp/common/test/rules/namenotreferredusingaqualifiedidorthis/NameNotReferredUsingAQualifiedIdOrThis.ql new file mode 100644 index 0000000000..731d7b1f84 --- /dev/null +++ b/cpp/common/test/rules/namenotreferredusingaqualifiedidorthis/NameNotReferredUsingAQualifiedIdOrThis.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.namenotreferredusingaqualifiedidorthis.NameNotReferredUsingAQualifiedIdOrThis + +class TestFileQuery extends NameNotReferredUsingAQualifiedIdOrThisSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/M14-6-1/test.cpp b/cpp/common/test/rules/namenotreferredusingaqualifiedidorthis/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M14-6-1/test.cpp rename to cpp/common/test/rules/namenotreferredusingaqualifiedidorthis/test.cpp diff --git a/cpp/autosar/test/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThisAudit.expected b/cpp/common/test/rules/namenotreferredusingaqualifiedidorthisaudit/NameNotReferredUsingAQualifiedIdOrThisAudit.expected similarity index 100% rename from cpp/autosar/test/rules/M14-6-1/NameNotReferredUsingAQualifiedIdOrThisAudit.expected rename to cpp/common/test/rules/namenotreferredusingaqualifiedidorthisaudit/NameNotReferredUsingAQualifiedIdOrThisAudit.expected diff --git a/cpp/common/test/rules/namenotreferredusingaqualifiedidorthisaudit/NameNotReferredUsingAQualifiedIdOrThisAudit.ql b/cpp/common/test/rules/namenotreferredusingaqualifiedidorthisaudit/NameNotReferredUsingAQualifiedIdOrThisAudit.ql new file mode 100644 index 0000000000..46ffea0b3d --- /dev/null +++ b/cpp/common/test/rules/namenotreferredusingaqualifiedidorthisaudit/NameNotReferredUsingAQualifiedIdOrThisAudit.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.namenotreferredusingaqualifiedidorthisaudit.NameNotReferredUsingAQualifiedIdOrThisAudit + +class TestFileQuery extends NameNotReferredUsingAQualifiedIdOrThisAuditSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/namenotreferredusingaqualifiedidorthisaudit/test.cpp b/cpp/common/test/rules/namenotreferredusingaqualifiedidorthisaudit/test.cpp new file mode 100644 index 0000000000..b16e6b40dc --- /dev/null +++ b/cpp/common/test/rules/namenotreferredusingaqualifiedidorthisaudit/test.cpp @@ -0,0 +1,87 @@ +typedef int TYPE; +void g(); +void g1(); +int m; + +template class B { +public: + typedef T TYPE; + void g(); + int m; +}; + +template class A : B { +public: + void m1() { + m = 0; // NON_COMPLIANT + g(); // NON_COMPLIANT + TYPE t = 0; // NON_COMPLIANT[FALSE_NEGATIVE] + void (*p)() = &g; // NON_COMPLIANT + } + void m2() { + ::m = 0; // COMPLIANT + ::g(); // COMPLIANT + ::TYPE t1 = 0; // COMPLIANT + B::m = 0; // COMPLIANT + this->m = 0; // COMPLIANT + this->g(); // COMPLIANT + void (B::*p)() = &B::g; // COMPLIANT + typename B::TYPE t2 = 0; // COMPLIANT + g1(); // COMPLIANT, identifier not found in B + } + void m3(int m) { + m = 0; // COMPLIANT, hides member + } + void m4() { + int m = 0; + m = 0; // COMPLIANT, hides member + } +}; + +void f() { + A a; + a.m1(); + a.m2(); + a.m3(1); + a.m4(); +} + +class D { +public: + typedef int TYPE; + void g(); + void g(int x); + static void sg(); + static void sg(int x); + int m; +}; + +class C : D { +public: + void m1() { + m = 0; // COMPLIANT - does not apply to non-class templates + g(); // COMPLIANT - does not apply to non-class templates + sg(); // COMPLIANT - does not apply to non-class templates + TYPE t1 = 0; // COMPLIANT - does not apply to non-class templates + // void (*p)() = &g; // NON_COMPILABLE - not valid to take address of member + // function without qualifier + } +}; + +template class E : D { +public: + void m1() { + m = 0; // COMPLIANT - does not apply to non dependent base types + g(); // COMPLIANT - does not apply to non dependent base types + TYPE t1 = 0; // COMPLIANT - does not apply to non dependent base types + // void (*p)() = &g; // NON_COMPILABLE - not valid to take address of member + // function without qualifier + } +}; + +void f2() { + C c; + c.m1(); + E e; + e.m1(); +} \ No newline at end of file diff --git a/cpp/autosar/test/rules/A15-4-2/NoExceptFunctionThrows.expected b/cpp/common/test/rules/noexceptfunctionshouldnotpropagatetothecaller/NoexceptFunctionShouldNotPropagateToTheCaller.expected similarity index 99% rename from cpp/autosar/test/rules/A15-4-2/NoExceptFunctionThrows.expected rename to cpp/common/test/rules/noexceptfunctionshouldnotpropagatetothecaller/NoexceptFunctionShouldNotPropagateToTheCaller.expected index b2f8391b15..db392fd8f6 100644 --- a/cpp/autosar/test/rules/A15-4-2/NoExceptFunctionThrows.expected +++ b/cpp/common/test/rules/noexceptfunctionshouldnotpropagatetothecaller/NoexceptFunctionShouldNotPropagateToTheCaller.expected @@ -1,3 +1,9 @@ +problems +| test.cpp:4:6:4:15 | test_throw | test.cpp:5:3:5:20 | throw ... [ExceptionA] | test.cpp:4:6:4:15 | test_throw [ExceptionA] | Function test_throw is declared noexcept(true) but can throw exceptions of type ExceptionA. | +| test.cpp:10:6:10:27 | noexceptIndirectThrowA | test.cpp:8:17:8:34 | throw ... [ExceptionA] | test.cpp:10:6:10:27 | noexceptIndirectThrowA [ExceptionA] | Function noexceptIndirectThrowA is declared noexcept(true) but can throw exceptions of type ExceptionA. | +| test.cpp:12:6:12:24 | test_indirect_throw | test.cpp:8:17:8:34 | throw ... [ExceptionA] | test.cpp:12:6:12:24 | test_indirect_throw [ExceptionA] | Function test_indirect_throw is declared noexcept(true) but can throw exceptions of type ExceptionA. | +| test.cpp:16:6:16:26 | test_indirect_throw_2 | test.cpp:8:17:8:34 | throw ... [ExceptionA] | test.cpp:16:6:16:26 | test_indirect_throw_2 [ExceptionA] | Function test_indirect_throw_2 is declared noexcept(true) but can throw exceptions of type ExceptionA. | +| test.cpp:33:6:33:26 | test_indirect_throw_6 | test.cpp:8:17:8:34 | throw ... [ExceptionA] | test.cpp:33:6:33:26 | test_indirect_throw_6 [ExceptionA] | Function test_indirect_throw_6 is declared noexcept(true) but can throw exceptions of type ExceptionA. | edges | test.cpp:5:3:5:20 | throw ... [ExceptionA] | test.cpp:4:6:4:15 | test_throw [ExceptionA] | | test.cpp:8:6:8:11 | throwA [ExceptionA] | test.cpp:9:25:9:30 | call to throwA [ExceptionA] | @@ -11,9 +17,3 @@ edges | test.cpp:13:3:13:8 | call to throwA [ExceptionA] | test.cpp:12:6:12:24 | test_indirect_throw [ExceptionA] | | test.cpp:17:3:17:8 | call to throwA [ExceptionA] | test.cpp:16:6:16:26 | test_indirect_throw_2 [ExceptionA] | | test.cpp:34:3:34:16 | call to indirectThrowA [ExceptionA] | test.cpp:33:6:33:26 | test_indirect_throw_6 [ExceptionA] | -#select -| test.cpp:4:6:4:15 | test_throw | test.cpp:5:3:5:20 | throw ... [ExceptionA] | test.cpp:4:6:4:15 | test_throw [ExceptionA] | Function test_throw is declared noexcept(true) but can throw exceptions of type ExceptionA. | -| test.cpp:10:6:10:27 | noexceptIndirectThrowA | test.cpp:8:17:8:34 | throw ... [ExceptionA] | test.cpp:10:6:10:27 | noexceptIndirectThrowA [ExceptionA] | Function noexceptIndirectThrowA is declared noexcept(true) but can throw exceptions of type ExceptionA. | -| test.cpp:12:6:12:24 | test_indirect_throw | test.cpp:8:17:8:34 | throw ... [ExceptionA] | test.cpp:12:6:12:24 | test_indirect_throw [ExceptionA] | Function test_indirect_throw is declared noexcept(true) but can throw exceptions of type ExceptionA. | -| test.cpp:16:6:16:26 | test_indirect_throw_2 | test.cpp:8:17:8:34 | throw ... [ExceptionA] | test.cpp:16:6:16:26 | test_indirect_throw_2 [ExceptionA] | Function test_indirect_throw_2 is declared noexcept(true) but can throw exceptions of type ExceptionA. | -| test.cpp:33:6:33:26 | test_indirect_throw_6 | test.cpp:8:17:8:34 | throw ... [ExceptionA] | test.cpp:33:6:33:26 | test_indirect_throw_6 [ExceptionA] | Function test_indirect_throw_6 is declared noexcept(true) but can throw exceptions of type ExceptionA. | diff --git a/cpp/common/test/rules/noexceptfunctionshouldnotpropagatetothecaller/NoexceptFunctionShouldNotPropagateToTheCaller.ql b/cpp/common/test/rules/noexceptfunctionshouldnotpropagatetothecaller/NoexceptFunctionShouldNotPropagateToTheCaller.ql new file mode 100644 index 0000000000..e8906287da --- /dev/null +++ b/cpp/common/test/rules/noexceptfunctionshouldnotpropagatetothecaller/NoexceptFunctionShouldNotPropagateToTheCaller.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.noexceptfunctionshouldnotpropagatetothecaller.NoexceptFunctionShouldNotPropagateToTheCaller + +class TestFileQuery extends NoexceptFunctionShouldNotPropagateToTheCallerSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/A15-4-2/test.cpp b/cpp/common/test/rules/noexceptfunctionshouldnotpropagatetothecaller/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A15-4-2/test.cpp rename to cpp/common/test/rules/noexceptfunctionshouldnotpropagatetothecaller/test.cpp diff --git a/cpp/autosar/test/rules/M7-3-2/IdentifierMainUsedForAFunctionOtherThanTheGlobalFunctionMain.expected b/cpp/common/test/rules/nonglobalfunctionmain/NonGlobalFunctionMain.expected similarity index 100% rename from cpp/autosar/test/rules/M7-3-2/IdentifierMainUsedForAFunctionOtherThanTheGlobalFunctionMain.expected rename to cpp/common/test/rules/nonglobalfunctionmain/NonGlobalFunctionMain.expected diff --git a/cpp/common/test/rules/nonglobalfunctionmain/NonGlobalFunctionMain.ql b/cpp/common/test/rules/nonglobalfunctionmain/NonGlobalFunctionMain.ql new file mode 100644 index 0000000000..02edcf3732 --- /dev/null +++ b/cpp/common/test/rules/nonglobalfunctionmain/NonGlobalFunctionMain.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.nonglobalfunctionmain.NonGlobalFunctionMain + +class TestFileQuery extends NonGlobalFunctionMainSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/M7-3-2/test.cpp b/cpp/common/test/rules/nonglobalfunctionmain/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M7-3-2/test.cpp rename to cpp/common/test/rules/nonglobalfunctionmain/test.cpp diff --git a/cpp/common/test/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.expected b/cpp/common/test/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.expected new file mode 100644 index 0000000000..3051e32537 --- /dev/null +++ b/cpp/common/test/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.expected @@ -0,0 +1,21 @@ +| test.cpp:37:18:37:24 | \u001aG | Invalid hexadecimal escape in string literal at '\\x1AG"'. | +| test.cpp:40:18:40:23 | \u00029 | Invalid octal escape in string literal at '\\029"'. | +| test.cpp:43:18:43:24 | \n7 | Invalid octal escape in string literal at '\\0127"'. | +| test.cpp:44:18:44:24 | \r7 | Invalid octal escape in string literal at '\\0157"'. | +| test.cpp:46:19:46:29 | \n\n9 | Invalid octal escape in string literal at '\\0129"'. | +| test.cpp:47:19:47:28 | \n\u00019 | Invalid octal escape in string literal at '\\019"'. | +| test.cpp:50:19:50:31 | \nAAA\u000f | Invalid octal escape in string literal at '\\012AAA\\017"'. | +| test.cpp:53:19:53:39 | Some Data \n\u000fA | Invalid octal escape in string literal at '\\017A"'. | +| test.cpp:54:19:55:21 | Some Data \n\u000fA5 | Invalid octal escape in string literal at '\\017A"\n "5"'. | +| test.cpp:56:19:58:25 | Some Data \n\u000fA\n1 | Invalid octal escape in string literal at '\\0121"'. | +| test.cpp:62:19:63:26 | \u0011G\u00012 | Invalid octal escape in string literal at '\\0012"'. | +| test.cpp:64:19:65:25 | \u0011GG\u0001 | Invalid hexadecimal escape in string literal at '\\x11G"\n "G\\001"'. | +| test.cpp:66:19:67:26 | \u0011GG\u00013 | Invalid hexadecimal escape in string literal at '\\x11G"\n "G\\0013"'. | +| test.cpp:66:19:67:26 | \u0011GG\u00013 | Invalid octal escape in string literal at '\\0013"'. | +| test.cpp:73:18:73:42 | Some Data \n\u000fA5 | Invalid octal escape in string literal at '\\017A" "5"'. | +| test.cpp:74:18:74:49 | Some Data \n\u000fA\n1 | Invalid octal escape in string literal at '\\0121"'. | +| test.cpp:76:18:76:32 | \u0011G\u00012 | Invalid octal escape in string literal at '\\0012"'. | +| test.cpp:77:18:77:32 | \u0011GG\u0001 | Invalid hexadecimal escape in string literal at '\\x11G" "G\\001"'. | +| test.cpp:78:18:78:33 | \u0011GG\u00013 | Invalid hexadecimal escape in string literal at '\\x11G" "G\\0013"'. | +| test.cpp:78:18:78:33 | \u0011GG\u00013 | Invalid octal escape in string literal at '\\0013"'. | +| test.cpp:81:11:81:16 | 10 | Invalid hexadecimal escape in string literal at '\\x0a''. | diff --git a/cpp/common/test/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.ql b/cpp/common/test/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.ql new file mode 100644 index 0000000000..c1aae3c31b --- /dev/null +++ b/cpp/common/test/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.nonterminatedescapesequences.NonTerminatedEscapeSequences + +class TestFileQuery extends NonTerminatedEscapeSequencesSharedQuery, TestQuery { } diff --git a/c/misra/test/rules/RULE-4-1/test.c b/cpp/common/test/rules/nonterminatedescapesequences/test.cpp similarity index 61% rename from c/misra/test/rules/RULE-4-1/test.c rename to cpp/common/test/rules/nonterminatedescapesequences/test.cpp index 4a0dcaa6ac..aa1093b791 100644 --- a/c/misra/test/rules/RULE-4-1/test.c +++ b/cpp/common/test/rules/nonterminatedescapesequences/test.cpp @@ -1,3 +1,31 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +#include + +struct SampleStruct { + int x1 : 1; // NON_COMPLIANT: very likely be signed, but if it's not, the + // query will automatically handle it since we use signed(), not + // isExplicitlySigned(). + signed int x2 : 1; // NON_COMPLIANT: single-bit named field with a signed type + signed char + x3 : 1; // NON_COMPLIANT: single-bit named field with a signed type + signed short + x4 : 1; // NON_COMPLIANT: single-bit named field with a signed type + unsigned int + x5 : 1; // COMPLIANT: single-bit named field but with an unsigned type + signed int x6 : 2; // COMPLIANT: named field with a signed type but declared + // to carry more than 1 bit + signed char : 1; // COMPLIANT: single-bit bit-field but unnamed +} sample_struct; + +struct S { + signed int x : 1; // NON-COMPLIANT + signed int y : 5; // COMPLIANT + signed int z : 7; // COMPLIANT + signed int : 0; // COMPLIANT + signed int : 1; // COMPLIANT + signed int : 2; // COMPLIANT +}; const char *a1 = "\x11" "G"; // COMPLIANT diff --git a/cpp/common/test/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.expected b/cpp/common/test/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.expected new file mode 100644 index 0000000000..662a21b5d6 --- /dev/null +++ b/cpp/common/test/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.expected @@ -0,0 +1 @@ +| test.cpp:5:19:5:20 | c4 | Nonunique value of enum constant compared to $@ | test.cpp:5:23:5:24 | c5 | c5 | diff --git a/cpp/common/test/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.ql b/cpp/common/test/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.ql new file mode 100644 index 0000000000..97ba6f516e --- /dev/null +++ b/cpp/common/test/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.nonuniqueenumerationconstant.NonUniqueEnumerationConstant + +class TestFileQuery extends NonUniqueEnumerationConstantSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/nonuniqueenumerationconstant/test.cpp b/cpp/common/test/rules/nonuniqueenumerationconstant/test.cpp new file mode 100644 index 0000000000..0712cb59e4 --- /dev/null +++ b/cpp/common/test/rules/nonuniqueenumerationconstant/test.cpp @@ -0,0 +1,6 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +enum e { c = 3 }; // COMPLIANT +enum e1 { c1 = 3, c2 }; // COMPLIANT +enum e3 { c3 = 3, c4, c5 = 4 }; // NON_COMPLIANT +enum e4 { c6 = 3, c7, c8, c9 = 6 }; // COMPLIANT \ No newline at end of file diff --git a/cpp/autosar/test/rules/A4-10-1/NullPointerConstantNotNullptr.expected b/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.expected similarity index 100% rename from cpp/autosar/test/rules/A4-10-1/NullPointerConstantNotNullptr.expected rename to cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.expected diff --git a/cpp/autosar/test/rules/A4-10-1/NullPointerConstantNotNullptr.expected.clang b/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.expected.clang similarity index 100% rename from cpp/autosar/test/rules/A4-10-1/NullPointerConstantNotNullptr.expected.clang rename to cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.expected.clang diff --git a/cpp/autosar/test/rules/A4-10-1/NullPointerConstantNotNullptr.expected.gcc b/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.expected.gcc similarity index 100% rename from cpp/autosar/test/rules/A4-10-1/NullPointerConstantNotNullptr.expected.gcc rename to cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.expected.gcc diff --git a/cpp/autosar/test/rules/A4-10-1/NullPointerConstantNotNullptr.expected.qcc b/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.expected.qcc similarity index 100% rename from cpp/autosar/test/rules/A4-10-1/NullPointerConstantNotNullptr.expected.qcc rename to cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.expected.qcc diff --git a/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.ql b/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.ql new file mode 100644 index 0000000000..e3d6c4841f --- /dev/null +++ b/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.nullptrnottheonlyformofthenullpointerconstant.NullptrNotTheOnlyFormOfTheNullPointerConstant + +class TestFileQuery extends NullptrNotTheOnlyFormOfTheNullPointerConstantSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/A4-10-1/test.cpp b/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A4-10-1/test.cpp rename to cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/test.cpp diff --git a/cpp/autosar/test/rules/A4-10-1/test.cpp.clang b/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/test.cpp.clang similarity index 100% rename from cpp/autosar/test/rules/A4-10-1/test.cpp.clang rename to cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/test.cpp.clang diff --git a/cpp/autosar/test/rules/A4-10-1/test.cpp.gcc b/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/test.cpp.gcc similarity index 100% rename from cpp/autosar/test/rules/A4-10-1/test.cpp.gcc rename to cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/test.cpp.gcc diff --git a/cpp/autosar/test/rules/A4-10-1/test.cpp.qcc b/cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/test.cpp.qcc similarity index 100% rename from cpp/autosar/test/rules/A4-10-1/test.cpp.qcc rename to cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/test.cpp.qcc diff --git a/cpp/autosar/test/rules/M12-1-1/DynamicTypeOfThisUsedFromConstructorOrDestructor.expected b/cpp/common/test/rules/objectsdynamictypeusedfromconstructorordestructor/ObjectsDynamicTypeUsedFromConstructorOrDestructor.expected similarity index 100% rename from cpp/autosar/test/rules/M12-1-1/DynamicTypeOfThisUsedFromConstructorOrDestructor.expected rename to cpp/common/test/rules/objectsdynamictypeusedfromconstructorordestructor/ObjectsDynamicTypeUsedFromConstructorOrDestructor.expected diff --git a/cpp/common/test/rules/objectsdynamictypeusedfromconstructorordestructor/ObjectsDynamicTypeUsedFromConstructorOrDestructor.ql b/cpp/common/test/rules/objectsdynamictypeusedfromconstructorordestructor/ObjectsDynamicTypeUsedFromConstructorOrDestructor.ql new file mode 100644 index 0000000000..151af6a5a3 --- /dev/null +++ b/cpp/common/test/rules/objectsdynamictypeusedfromconstructorordestructor/ObjectsDynamicTypeUsedFromConstructorOrDestructor.ql @@ -0,0 +1,5 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.objectsdynamictypeusedfromconstructorordestructor.ObjectsDynamicTypeUsedFromConstructorOrDestructor + +class TestFileQuery extends ObjectsDynamicTypeUsedFromConstructorOrDestructorSharedQuery, TestQuery { +} diff --git a/cpp/autosar/test/rules/M12-1-1/test.cpp b/cpp/common/test/rules/objectsdynamictypeusedfromconstructorordestructor/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M12-1-1/test.cpp rename to cpp/common/test/rules/objectsdynamictypeusedfromconstructorordestructor/test.cpp diff --git a/cpp/common/test/rules/overridingshallspecifydifferentdefaultarguments/OverridingShallSpecifyDifferentDefaultArguments.expected b/cpp/common/test/rules/overridingshallspecifydifferentdefaultarguments/OverridingShallSpecifyDifferentDefaultArguments.expected new file mode 100644 index 0000000000..d2d80e0572 --- /dev/null +++ b/cpp/common/test/rules/overridingshallspecifydifferentdefaultarguments/OverridingShallSpecifyDifferentDefaultArguments.expected @@ -0,0 +1,2 @@ +| test.cpp:16:8:16:8 | f | Overriding function does not have the same default parameters as $@ | test.cpp:4:16:4:16 | f | overridden function | +| test.cpp:21:8:21:8 | f | Overriding function does not have the same default parameters as $@ | test.cpp:4:16:4:16 | f | overridden function | diff --git a/cpp/common/test/rules/overridingshallspecifydifferentdefaultarguments/OverridingShallSpecifyDifferentDefaultArguments.ql b/cpp/common/test/rules/overridingshallspecifydifferentdefaultarguments/OverridingShallSpecifyDifferentDefaultArguments.ql new file mode 100644 index 0000000000..2bb15bb684 --- /dev/null +++ b/cpp/common/test/rules/overridingshallspecifydifferentdefaultarguments/OverridingShallSpecifyDifferentDefaultArguments.ql @@ -0,0 +1,5 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.overridingshallspecifydifferentdefaultarguments.OverridingShallSpecifyDifferentDefaultArguments + +class TestFileQuery extends OverridingShallSpecifyDifferentDefaultArgumentsSharedQuery, TestQuery { +} diff --git a/cpp/autosar/test/rules/M8-3-1/test.cpp b/cpp/common/test/rules/overridingshallspecifydifferentdefaultarguments/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M8-3-1/test.cpp rename to cpp/common/test/rules/overridingshallspecifydifferentdefaultarguments/test.cpp diff --git a/cpp/autosar/test/rules/A5-10-1/PointerToMemberVirtualFunctionWithNullPointerConstant.expected b/cpp/common/test/rules/potentiallyvirtualpointeronlycomparestonullptr/PotentiallyVirtualPointerOnlyComparesToNullptr.expected similarity index 63% rename from cpp/autosar/test/rules/A5-10-1/PointerToMemberVirtualFunctionWithNullPointerConstant.expected rename to cpp/common/test/rules/potentiallyvirtualpointeronlycomparestonullptr/PotentiallyVirtualPointerOnlyComparesToNullptr.expected index 81f26e5130..71c0662377 100644 --- a/cpp/autosar/test/rules/A5-10-1/PointerToMemberVirtualFunctionWithNullPointerConstant.expected +++ b/cpp/common/test/rules/potentiallyvirtualpointeronlycomparestonullptr/PotentiallyVirtualPointerOnlyComparesToNullptr.expected @@ -1,2 +1,2 @@ -| test.cpp:14:14:14:29 | ... == ... | A pointer to member virtual function $@ is tested for equality with non-null-pointer-constant $@. | test.cpp:6:16:6:17 | F3 | F3 | test.cpp:14:24:14:29 | F1 | F1 | -| test.cpp:15:14:15:29 | ... == ... | A pointer to member virtual function $@ is tested for equality with non-null-pointer-constant $@. | test.cpp:6:16:6:17 | F3 | F3 | test.cpp:15:24:15:29 | F2 | F2 | +| test.cpp:14:14:14:29 | ... == ... | A pointer to member virtual function $@ is tested for equality with non-null-pointer-constant $@. | test.cpp:6:16:6:17 | F3 | F3 | test.cpp:14:24:14:29 | F1 | F1 | +| test.cpp:15:14:15:29 | ... == ... | A pointer to member virtual function $@ is tested for equality with non-null-pointer-constant $@. | test.cpp:6:16:6:17 | F3 | F3 | test.cpp:15:24:15:29 | F2 | F2 | diff --git a/cpp/common/test/rules/potentiallyvirtualpointeronlycomparestonullptr/PotentiallyVirtualPointerOnlyComparesToNullptr.ql b/cpp/common/test/rules/potentiallyvirtualpointeronlycomparestonullptr/PotentiallyVirtualPointerOnlyComparesToNullptr.ql new file mode 100644 index 0000000000..84263abc91 --- /dev/null +++ b/cpp/common/test/rules/potentiallyvirtualpointeronlycomparestonullptr/PotentiallyVirtualPointerOnlyComparesToNullptr.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.potentiallyvirtualpointeronlycomparestonullptr.PotentiallyVirtualPointerOnlyComparesToNullptr + +class TestFileQuery extends PotentiallyVirtualPointerOnlyComparesToNullptrSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/A5-10-1/test.cpp b/cpp/common/test/rules/potentiallyvirtualpointeronlycomparestonullptr/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A5-10-1/test.cpp rename to cpp/common/test/rules/potentiallyvirtualpointeronlycomparestonullptr/test.cpp diff --git a/cpp/autosar/test/rules/A5-2-4/ReinterpretCastUsed.expected b/cpp/common/test/rules/reinterpretcastused/ReinterpretCastUsed.expected similarity index 100% rename from cpp/autosar/test/rules/A5-2-4/ReinterpretCastUsed.expected rename to cpp/common/test/rules/reinterpretcastused/ReinterpretCastUsed.expected diff --git a/cpp/common/test/rules/reinterpretcastused/ReinterpretCastUsed.ql b/cpp/common/test/rules/reinterpretcastused/ReinterpretCastUsed.ql new file mode 100644 index 0000000000..b58a7f4dbb --- /dev/null +++ b/cpp/common/test/rules/reinterpretcastused/ReinterpretCastUsed.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.reinterpretcastused.ReinterpretCastUsed + +class TestFileQuery extends ReinterpretCastUsedSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/A5-2-4/test.cpp b/cpp/common/test/rules/reinterpretcastused/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A5-2-4/test.cpp rename to cpp/common/test/rules/reinterpretcastused/test.cpp diff --git a/cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected b/cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected new file mode 100644 index 0000000000..3f2720dd76 --- /dev/null +++ b/cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.expected @@ -0,0 +1,3 @@ +| test.cpp:9:7:9:12 | ... = ... | Use of an assignment operator's result. | +| test.cpp:13:11:13:16 | ... = ... | Use of an assignment operator's result. | +| test.cpp:15:8:15:13 | ... = ... | Use of an assignment operator's result. | diff --git a/cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql b/cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql new file mode 100644 index 0000000000..286e4424a4 --- /dev/null +++ b/cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.resultofanassignmentoperatorshouldnotbeused.ResultOfAnAssignmentOperatorShouldNotBeUsed + +class TestFileQuery extends ResultOfAnAssignmentOperatorShouldNotBeUsedSharedQuery, TestQuery { } diff --git a/c/misra/test/rules/RULE-13-4/test.c b/cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/test.cpp similarity index 59% rename from c/misra/test/rules/RULE-13-4/test.c rename to cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/test.cpp index aeabb60fac..21fb4c0910 100644 --- a/c/misra/test/rules/RULE-13-4/test.c +++ b/cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/test.cpp @@ -1,3 +1,5 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. void test() { int l1, l2; int l3[1]; diff --git a/cpp/autosar/test/rules/M7-5-1/FunctionReturnAutomaticVarCondition.expected b/cpp/common/test/rules/returnreferenceorpointertoautomaticlocalvariable/ReturnReferenceOrPointerToAutomaticLocalVariable.expected similarity index 100% rename from cpp/autosar/test/rules/M7-5-1/FunctionReturnAutomaticVarCondition.expected rename to cpp/common/test/rules/returnreferenceorpointertoautomaticlocalvariable/ReturnReferenceOrPointerToAutomaticLocalVariable.expected diff --git a/cpp/common/test/rules/returnreferenceorpointertoautomaticlocalvariable/ReturnReferenceOrPointerToAutomaticLocalVariable.ql b/cpp/common/test/rules/returnreferenceorpointertoautomaticlocalvariable/ReturnReferenceOrPointerToAutomaticLocalVariable.ql new file mode 100644 index 0000000000..c6c9c9e8fc --- /dev/null +++ b/cpp/common/test/rules/returnreferenceorpointertoautomaticlocalvariable/ReturnReferenceOrPointerToAutomaticLocalVariable.ql @@ -0,0 +1,5 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.returnreferenceorpointertoautomaticlocalvariable.ReturnReferenceOrPointerToAutomaticLocalVariable + +class TestFileQuery extends ReturnReferenceOrPointerToAutomaticLocalVariableSharedQuery, TestQuery { +} diff --git a/cpp/autosar/test/rules/M7-5-1/test.cpp b/cpp/common/test/rules/returnreferenceorpointertoautomaticlocalvariable/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M7-5-1/test.cpp rename to cpp/common/test/rules/returnreferenceorpointertoautomaticlocalvariable/test.cpp diff --git a/cpp/autosar/test/rules/M6-3-1/SwitchCompoundCondition.expected b/cpp/common/test/rules/switchcompoundcondition/SwitchCompoundCondition.expected similarity index 100% rename from cpp/autosar/test/rules/M6-3-1/SwitchCompoundCondition.expected rename to cpp/common/test/rules/switchcompoundcondition/SwitchCompoundCondition.expected diff --git a/cpp/common/test/rules/switchcompoundcondition/SwitchCompoundCondition.ql b/cpp/common/test/rules/switchcompoundcondition/SwitchCompoundCondition.ql new file mode 100644 index 0000000000..8fb855036c --- /dev/null +++ b/cpp/common/test/rules/switchcompoundcondition/SwitchCompoundCondition.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.switchcompoundcondition.SwitchCompoundCondition + +class TestFileQuery extends SwitchCompoundConditionSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/switchcompoundcondition/test.cpp b/cpp/common/test/rules/switchcompoundcondition/test.cpp new file mode 100644 index 0000000000..487c007fdc --- /dev/null +++ b/cpp/common/test/rules/switchcompoundcondition/test.cpp @@ -0,0 +1,56 @@ +void test_loop_missing_braces(int expression) { + for (int i = 0; i < expression; i++) // BAD + expression = expression % 2; +} + +void test_loop_valid_braces_check(int expression) { + for (int i = 0; i < expression; i++) { // GOOD + expression = expression % 2; + } + + int j = 10; + while (expression < 10) // BAD + j = j + 10; +} + +void test_loop_mix_validity(int expression) { + do // BAD + expression = expression % 2; + while (expression < 10); + + while (expression > 10) // GOOD + { + expression = expression * 2; + } + + do { // GOOD + expression = expression % 2; + } while (expression < 5); +} + +void test_switch_valid_braces(int i, int expression) { + // GOOD + switch (expression) { + case 0: + while (i < 10) { + i = i + expression; + } + break; + case 1: + if (i > 10) { + i = i * i; + } + break; + default: + break; + } +} + +void test_switch_invalid_braces(int i, int expression) { + // BAD + switch (expression) + case 0: + while (i < 10) { + i = i + expression; + } +} diff --git a/cpp/autosar/test/rules/M2-13-3/MissingUSuffix.expected b/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/UnsignedIntegerLiteralsNotAppropriatelySuffixed.expected similarity index 100% rename from cpp/autosar/test/rules/M2-13-3/MissingUSuffix.expected rename to cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/UnsignedIntegerLiteralsNotAppropriatelySuffixed.expected diff --git a/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/UnsignedIntegerLiteralsNotAppropriatelySuffixed.ql b/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/UnsignedIntegerLiteralsNotAppropriatelySuffixed.ql new file mode 100644 index 0000000000..30f07a3f22 --- /dev/null +++ b/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/UnsignedIntegerLiteralsNotAppropriatelySuffixed.ql @@ -0,0 +1,5 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.unsignedintegerliteralsnotappropriatelysuffixed.UnsignedIntegerLiteralsNotAppropriatelySuffixed + +class TestFileQuery extends UnsignedIntegerLiteralsNotAppropriatelySuffixedSharedQuery, TestQuery { +} diff --git a/cpp/autosar/test/rules/M2-13-3/test.cpp b/cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M2-13-3/test.cpp rename to cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/test.cpp diff --git a/cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.expected b/cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.expected new file mode 100644 index 0000000000..3902cae09d --- /dev/null +++ b/cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.expected @@ -0,0 +1,4 @@ +| test.cpp:7:3:7:9 | ... + ... | Operation + of type unsigned int may wrap. | +| test.cpp:8:3:8:10 | ... += ... | Operation += of type unsigned int may wrap. | +| test.cpp:61:3:61:9 | ... - ... | Operation - of type unsigned int may wrap. | +| test.cpp:62:3:62:10 | ... -= ... | Operation -= of type unsigned int may wrap. | diff --git a/cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.ql b/cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.ql new file mode 100644 index 0000000000..b88e7637c1 --- /dev/null +++ b/cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.unsignedoperationwithconstantoperandswraps.UnsignedOperationWithConstantOperandsWraps + +class TestFileQuery extends UnsignedOperationWithConstantOperandsWrapsSharedQuery, TestQuery { } diff --git a/c/cert/test/rules/INT30-C/test.c b/cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/test.cpp similarity index 94% rename from c/cert/test/rules/INT30-C/test.c rename to cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/test.cpp index 433cf534f4..8f76fbeeeb 100644 --- a/c/cert/test/rules/INT30-C/test.c +++ b/cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/test.cpp @@ -1,3 +1,6 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. + #include void test_add_simple(unsigned int i1, unsigned int i2) { diff --git a/cpp/common/test/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.expected b/cpp/common/test/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.expected new file mode 100644 index 0000000000..e4280f2f1a --- /dev/null +++ b/cpp/common/test/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.expected @@ -0,0 +1,2 @@ +| test.cpp:5:3:5:5 | 10 | Non zero octal literal 012. | +| test.cpp:6:3:6:5 | 44 | Non zero octal literal 054. | diff --git a/cpp/common/test/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.ql b/cpp/common/test/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.ql new file mode 100644 index 0000000000..0404a7bc0c --- /dev/null +++ b/cpp/common/test/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.useofnonzerooctalliteral.UseOfNonZeroOctalLiteral + +class TestFileQuery extends UseOfNonZeroOctalLiteralSharedQuery, TestQuery { } diff --git a/cpp/common/test/rules/useofnonzerooctalliteral/test.cpp b/cpp/common/test/rules/useofnonzerooctalliteral/test.cpp new file mode 100644 index 0000000000..0bf928c9ec --- /dev/null +++ b/cpp/common/test/rules/useofnonzerooctalliteral/test.cpp @@ -0,0 +1,7 @@ +// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND +// CHANGES SHOULD BE REFLECTED THERE AS WELL. +void test_non_zero_octal() { + 0; // COMPLIANT - octal literal zero permitted + 012; // NON_COMPLIANT + 054; // NON_COMPLIANT +} \ No newline at end of file diff --git a/cpp/autosar/test/rules/A18-1-2/VectorboolSpecializationUsed.expected b/cpp/common/test/rules/vectorshouldnotbespecializedwithbool/VectorShouldNotBeSpecializedWithBool.expected similarity index 100% rename from cpp/autosar/test/rules/A18-1-2/VectorboolSpecializationUsed.expected rename to cpp/common/test/rules/vectorshouldnotbespecializedwithbool/VectorShouldNotBeSpecializedWithBool.expected diff --git a/cpp/autosar/test/rules/A18-1-2/VectorboolSpecializationUsed.expected.qcc b/cpp/common/test/rules/vectorshouldnotbespecializedwithbool/VectorShouldNotBeSpecializedWithBool.expected.qcc similarity index 100% rename from cpp/autosar/test/rules/A18-1-2/VectorboolSpecializationUsed.expected.qcc rename to cpp/common/test/rules/vectorshouldnotbespecializedwithbool/VectorShouldNotBeSpecializedWithBool.expected.qcc diff --git a/cpp/common/test/rules/vectorshouldnotbespecializedwithbool/VectorShouldNotBeSpecializedWithBool.ql b/cpp/common/test/rules/vectorshouldnotbespecializedwithbool/VectorShouldNotBeSpecializedWithBool.ql new file mode 100644 index 0000000000..a965d5e5d6 --- /dev/null +++ b/cpp/common/test/rules/vectorshouldnotbespecializedwithbool/VectorShouldNotBeSpecializedWithBool.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.vectorshouldnotbespecializedwithbool.VectorShouldNotBeSpecializedWithBool + +class TestFileQuery extends VectorShouldNotBeSpecializedWithBoolSharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/A18-1-2/test.cpp b/cpp/common/test/rules/vectorshouldnotbespecializedwithbool/test.cpp similarity index 100% rename from cpp/autosar/test/rules/A18-1-2/test.cpp rename to cpp/common/test/rules/vectorshouldnotbespecializedwithbool/test.cpp diff --git a/cpp/autosar/test/rules/M10-1-3/AccessibleBaseClassBothVirtualAndNonVirtualInHierarchy.expected b/cpp/common/test/rules/virtualandnonvirtualclassinthehierarchy/VirtualAndNonVirtualClassInTheHierarchy.expected similarity index 100% rename from cpp/autosar/test/rules/M10-1-3/AccessibleBaseClassBothVirtualAndNonVirtualInHierarchy.expected rename to cpp/common/test/rules/virtualandnonvirtualclassinthehierarchy/VirtualAndNonVirtualClassInTheHierarchy.expected diff --git a/cpp/common/test/rules/virtualandnonvirtualclassinthehierarchy/VirtualAndNonVirtualClassInTheHierarchy.ql b/cpp/common/test/rules/virtualandnonvirtualclassinthehierarchy/VirtualAndNonVirtualClassInTheHierarchy.ql new file mode 100644 index 0000000000..2137cbeb66 --- /dev/null +++ b/cpp/common/test/rules/virtualandnonvirtualclassinthehierarchy/VirtualAndNonVirtualClassInTheHierarchy.ql @@ -0,0 +1,4 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.virtualandnonvirtualclassinthehierarchy.VirtualAndNonVirtualClassInTheHierarchy + +class TestFileQuery extends VirtualAndNonVirtualClassInTheHierarchySharedQuery, TestQuery { } diff --git a/cpp/autosar/test/rules/M10-1-3/test.cpp b/cpp/common/test/rules/virtualandnonvirtualclassinthehierarchy/test.cpp similarity index 100% rename from cpp/autosar/test/rules/M10-1-3/test.cpp rename to cpp/common/test/rules/virtualandnonvirtualclassinthehierarchy/test.cpp diff --git a/cpp/misra/src/rules/DIR-15-8-1/CopyAndMoveAssignmentsShallHandleSelfAssignment.ql b/cpp/misra/src/rules/DIR-15-8-1/CopyAndMoveAssignmentsShallHandleSelfAssignment.ql new file mode 100644 index 0000000000..daf6e89530 --- /dev/null +++ b/cpp/misra/src/rules/DIR-15-8-1/CopyAndMoveAssignmentsShallHandleSelfAssignment.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/copy-and-move-assignments-shall-handle-self-assignment + * @name DIR-15-8-1: User-provided copy assignment operators and move assignment operators shall handle self-assignment + * @description User-provided copy assignment operators and move assignment operators shall handle + * self-assignment. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/dir-15-8-1 + * external/misra/allocated-target/implementation + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.copyandmoveassignmentsshallhandleselfassignment.CopyAndMoveAssignmentsShallHandleSelfAssignment + +class CopyAndMoveAssignmentsShallHandleSelfAssignmentQuery extends CopyAndMoveAssignmentsShallHandleSelfAssignmentSharedQuery +{ + CopyAndMoveAssignmentsShallHandleSelfAssignmentQuery() { + this = ImportMisra23Package::copyAndMoveAssignmentsShallHandleSelfAssignmentQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-10-0-1/UseSingleGlobalOrMemberDeclarators.ql b/cpp/misra/src/rules/RULE-10-0-1/UseSingleGlobalOrMemberDeclarators.ql new file mode 100644 index 0000000000..ffbc5bacaf --- /dev/null +++ b/cpp/misra/src/rules/RULE-10-0-1/UseSingleGlobalOrMemberDeclarators.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/use-single-global-or-member-declarators + * @name RULE-10-0-1: Multiple declarations in the same global or member declaration sequence + * @description A declaration should not declare more than one variable or member variable. + * @kind problem + * @precision medium + * @problem.severity recommendation + * @tags external/misra/id/rule-10-0-1 + * readability + * maintainability + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.multipleglobalormemberdeclarators.MultipleGlobalOrMemberDeclarators + +class UseSingleGlobalOrMemberDeclaratorsQuery extends MultipleGlobalOrMemberDeclaratorsSharedQuery { + UseSingleGlobalOrMemberDeclaratorsQuery() { + this = ImportMisra23Package::useSingleGlobalOrMemberDeclaratorsQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-10-0-1/UseSingleLocalDeclarators.ql b/cpp/misra/src/rules/RULE-10-0-1/UseSingleLocalDeclarators.ql new file mode 100644 index 0000000000..6d756daa87 --- /dev/null +++ b/cpp/misra/src/rules/RULE-10-0-1/UseSingleLocalDeclarators.ql @@ -0,0 +1,22 @@ +/** + * @id cpp/misra/use-single-local-declarators + * @name RULE-10-0-1: Multiple declarations in the same local statement + * @description A declaration should not declare more than one variable or member variable. + * @kind problem + * @precision very-high + * @problem.severity recommendation + * @tags external/misra/id/rule-10-0-1 + * readability + * maintainability + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.multiplelocaldeclarators.MultipleLocalDeclarators + +class UseSingleLocalDeclaratorsQuery extends MultipleLocalDeclaratorsSharedQuery { + UseSingleLocalDeclaratorsQuery() { this = ImportMisra23Package::useSingleLocalDeclaratorsQuery() } +} diff --git a/cpp/misra/src/rules/RULE-10-2-1/EnumerationNotDefinedWithAnExplicitUnderlyingType.ql b/cpp/misra/src/rules/RULE-10-2-1/EnumerationNotDefinedWithAnExplicitUnderlyingType.ql new file mode 100644 index 0000000000..ab4b6a19a1 --- /dev/null +++ b/cpp/misra/src/rules/RULE-10-2-1/EnumerationNotDefinedWithAnExplicitUnderlyingType.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/enumeration-not-defined-with-an-explicit-underlying-type + * @name RULE-10-2-1: An enumeration shall be defined with an explicit underlying type + * @description An enumeration shall be defined with an explicit underlying type. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-10-2-1 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.enumerationnotdefinedwithanexplicitunderlyingtype.EnumerationNotDefinedWithAnExplicitUnderlyingType + +class EnumerationNotDefinedWithAnExplicitUnderlyingTypeQuery extends EnumerationNotDefinedWithAnExplicitUnderlyingTypeSharedQuery +{ + EnumerationNotDefinedWithAnExplicitUnderlyingTypeQuery() { + this = ImportMisra23Package::enumerationNotDefinedWithAnExplicitUnderlyingTypeQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-10-4-1/AsmDeclarationShallNotBeUsed.ql b/cpp/misra/src/rules/RULE-10-4-1/AsmDeclarationShallNotBeUsed.ql new file mode 100644 index 0000000000..5a2f4c4265 --- /dev/null +++ b/cpp/misra/src/rules/RULE-10-4-1/AsmDeclarationShallNotBeUsed.ql @@ -0,0 +1,22 @@ +/** + * @id cpp/misra/asm-declaration-shall-not-be-used + * @name RULE-10-4-1: The asm declaration shall not be used + * @description The asm declaration shall not be used. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-10-4-1 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.asmdeclarationused.AsmDeclarationUsed + +class AsmDeclarationShallNotBeUsedQuery extends AsmDeclarationUsedSharedQuery { + AsmDeclarationShallNotBeUsedQuery() { + this = ImportMisra23Package::asmDeclarationShallNotBeUsedQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-11-6-3/NonUniqueEnumerationConstant.ql b/cpp/misra/src/rules/RULE-11-6-3/NonUniqueEnumerationConstant.ql new file mode 100644 index 0000000000..faa0880a75 --- /dev/null +++ b/cpp/misra/src/rules/RULE-11-6-3/NonUniqueEnumerationConstant.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/non-unique-enumeration-constant + * @name RULE-11-6-3: Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique + * @description Within an enumerator list, the value of an implicitly-specified enumeration constant + * shall be unique. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-11-6-3 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.nonuniqueenumerationconstant.NonUniqueEnumerationConstant + +class NonUniqueEnumerationConstantQuery extends NonUniqueEnumerationConstantSharedQuery { + NonUniqueEnumerationConstantQuery() { + this = ImportMisra23Package::nonUniqueEnumerationConstantQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-12-2-2/BitFieldShallHaveAnAppropriateType.ql b/cpp/misra/src/rules/RULE-12-2-2/BitFieldShallHaveAnAppropriateType.ql new file mode 100644 index 0000000000..f5041252f9 --- /dev/null +++ b/cpp/misra/src/rules/RULE-12-2-2/BitFieldShallHaveAnAppropriateType.ql @@ -0,0 +1,22 @@ +/** + * @id cpp/misra/bit-field-shall-have-an-appropriate-type + * @name RULE-12-2-2: A bit-field shall have an appropriate type + * @description A bit-field shall have an appropriate type. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-12-2-2 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.bitfieldshallhaveanappropriatetype.BitFieldShallHaveAnAppropriateType + +class BitFieldShallHaveAnAppropriateTypeQuery extends BitFieldShallHaveAnAppropriateTypeSharedQuery { + BitFieldShallHaveAnAppropriateTypeQuery() { + this = ImportMisra23Package::bitFieldShallHaveAnAppropriateTypeQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-12-2-3/SignedIntegerNamedBitFieldHaveALengthOfOneBit.ql b/cpp/misra/src/rules/RULE-12-2-3/SignedIntegerNamedBitFieldHaveALengthOfOneBit.ql new file mode 100644 index 0000000000..df547bbec8 --- /dev/null +++ b/cpp/misra/src/rules/RULE-12-2-3/SignedIntegerNamedBitFieldHaveALengthOfOneBit.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/signed-integer-named-bit-field-have-a-length-of-one-bit + * @name RULE-12-2-3: A named bit-field with signed integer type shall not have a length of one bit + * @description A named bit-field with signed integer type shall not have a length of one bit. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-12-2-3 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.namedbitfieldswithsignedintegertype.NamedBitFieldsWithSignedIntegerType + +class SignedIntegerNamedBitFieldHaveALengthOfOneBitQuery extends NamedBitFieldsWithSignedIntegerTypeSharedQuery +{ + SignedIntegerNamedBitFieldHaveALengthOfOneBitQuery() { + this = ImportMisra23Package::signedIntegerNamedBitFieldHaveALengthOfOneBitQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-13-1-2/VirtualAndNonVirtualClassInTheHierarchy.ql b/cpp/misra/src/rules/RULE-13-1-2/VirtualAndNonVirtualClassInTheHierarchy.ql new file mode 100644 index 0000000000..75030afbfb --- /dev/null +++ b/cpp/misra/src/rules/RULE-13-1-2/VirtualAndNonVirtualClassInTheHierarchy.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/virtual-and-non-virtual-class-in-the-hierarchy + * @name RULE-13-1-2: An accessible base class shall not be both virtual and non-virtual in the same hierarchy + * @description An accessible base class shall not be both virtual and non-virtual in the same + * hierarchy. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-13-1-2 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.virtualandnonvirtualclassinthehierarchy.VirtualAndNonVirtualClassInTheHierarchy + +class VirtualAndNonVirtualClassInTheHierarchyQuery extends VirtualAndNonVirtualClassInTheHierarchySharedQuery +{ + VirtualAndNonVirtualClassInTheHierarchyQuery() { + this = ImportMisra23Package::virtualAndNonVirtualClassInTheHierarchyQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-13-3-2/OverridingShallSpecifyDifferentDefaultArguments.ql b/cpp/misra/src/rules/RULE-13-3-2/OverridingShallSpecifyDifferentDefaultArguments.ql new file mode 100644 index 0000000000..519589984e --- /dev/null +++ b/cpp/misra/src/rules/RULE-13-3-2/OverridingShallSpecifyDifferentDefaultArguments.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/overriding-shall-specify-different-default-arguments + * @name RULE-13-3-2: Parameters in an overriding virtual function shall not specify different default arguments + * @description Parameters in an overriding virtual function shall not specify different default + * arguments. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-13-3-2 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.overridingshallspecifydifferentdefaultarguments.OverridingShallSpecifyDifferentDefaultArguments + +class OverridingShallSpecifyDifferentDefaultArgumentsQuery extends OverridingShallSpecifyDifferentDefaultArgumentsSharedQuery +{ + OverridingShallSpecifyDifferentDefaultArgumentsQuery() { + this = ImportMisra23Package::overridingShallSpecifyDifferentDefaultArgumentsQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-13-3-4/PotentiallyVirtualPointerOnlyComparesToNullptr.ql b/cpp/misra/src/rules/RULE-13-3-4/PotentiallyVirtualPointerOnlyComparesToNullptr.ql new file mode 100644 index 0000000000..1c528396e0 --- /dev/null +++ b/cpp/misra/src/rules/RULE-13-3-4/PotentiallyVirtualPointerOnlyComparesToNullptr.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/potentially-virtual-pointer-only-compares-to-nullptr + * @name RULE-13-3-4: A comparison of a potentially virtual pointer to member function shall only be with nullptr + * @description A comparison of a potentially virtual pointer to member function shall only be with + * nullptr. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-13-3-4 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.potentiallyvirtualpointeronlycomparestonullptr.PotentiallyVirtualPointerOnlyComparesToNullptr + +class PotentiallyVirtualPointerOnlyComparesToNullptrQuery extends PotentiallyVirtualPointerOnlyComparesToNullptrSharedQuery +{ + PotentiallyVirtualPointerOnlyComparesToNullptrQuery() { + this = ImportMisra23Package::potentiallyVirtualPointerOnlyComparesToNullptrQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-15-1-1/ObjectsDynamicTypeUsedFromConstructorOrDestructor.ql b/cpp/misra/src/rules/RULE-15-1-1/ObjectsDynamicTypeUsedFromConstructorOrDestructor.ql new file mode 100644 index 0000000000..f23c1afab8 --- /dev/null +++ b/cpp/misra/src/rules/RULE-15-1-1/ObjectsDynamicTypeUsedFromConstructorOrDestructor.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/objects-dynamic-type-used-from-constructor-or-destructor + * @name RULE-15-1-1: An object’s dynamic type shall not be used from within its constructor or destructor + * @description An object’s dynamic type shall not be used from within its constructor or + * destructor. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-15-1-1 + * scope/system + * external/misra/enforcement/undecidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.objectsdynamictypeusedfromconstructorordestructor.ObjectsDynamicTypeUsedFromConstructorOrDestructor + +class ObjectsDynamicTypeUsedFromConstructorOrDestructorQuery extends ObjectsDynamicTypeUsedFromConstructorOrDestructorSharedQuery +{ + ObjectsDynamicTypeUsedFromConstructorOrDestructorQuery() { + this = ImportMisra23Package::objectsDynamicTypeUsedFromConstructorOrDestructorQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-15-1-2/InitializeAllVirtualBaseClasses.ql b/cpp/misra/src/rules/RULE-15-1-2/InitializeAllVirtualBaseClasses.ql new file mode 100644 index 0000000000..3dd7b7e3e2 --- /dev/null +++ b/cpp/misra/src/rules/RULE-15-1-2/InitializeAllVirtualBaseClasses.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/initialize-all-virtual-base-classes + * @name RULE-15-1-2: All constructors of a class should explicitly initialize all of its virtual base classes and + * @description All constructors of a class should explicitly initialize all of its virtual base + * classes and immediate base classes. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-15-1-2 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.initializeallvirtualbaseclasses.InitializeAllVirtualBaseClasses + +class InitializeAllVirtualBaseClassesQuery extends InitializeAllVirtualBaseClassesSharedQuery { + InitializeAllVirtualBaseClassesQuery() { + this = ImportMisra23Package::initializeAllVirtualBaseClassesQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-15-1-5/InitializerListConstructorIsTheOnlyConstructor.ql b/cpp/misra/src/rules/RULE-15-1-5/InitializerListConstructorIsTheOnlyConstructor.ql new file mode 100644 index 0000000000..c7cf1856cd --- /dev/null +++ b/cpp/misra/src/rules/RULE-15-1-5/InitializerListConstructorIsTheOnlyConstructor.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/initializer-list-constructor-is-the-only-constructor + * @name RULE-15-1-5: A class shall only define an initializer-list constructor when it is the only constructor + * @description A class shall only define an initializer-list constructor when it is the only + * constructor. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-15-1-5 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.initializerlistconstructoristheonlyconstructor.InitializerListConstructorIsTheOnlyConstructor + +class InitializerListConstructorIsTheOnlyConstructorQuery extends InitializerListConstructorIsTheOnlyConstructorSharedQuery +{ + InitializerListConstructorIsTheOnlyConstructorQuery() { + this = ImportMisra23Package::initializerListConstructorIsTheOnlyConstructorQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-16-5-2/AddressOfOperatorOverloaded.ql b/cpp/misra/src/rules/RULE-16-5-2/AddressOfOperatorOverloaded.ql new file mode 100644 index 0000000000..937ec4e9e3 --- /dev/null +++ b/cpp/misra/src/rules/RULE-16-5-2/AddressOfOperatorOverloaded.ql @@ -0,0 +1,22 @@ +/** + * @id cpp/misra/address-of-operator-overloaded + * @name RULE-16-5-2: The address-of operator shall not be overloaded + * @description The address-of operator shall not be overloaded. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-16-5-2 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.addressofoperatoroverloaded.AddressOfOperatorOverloaded + +class AddressOfOperatorOverloadedQuery extends AddressOfOperatorOverloadedSharedQuery { + AddressOfOperatorOverloadedQuery() { + this = ImportMisra23Package::addressOfOperatorOverloadedQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-17-8-1/FunctionTemplatesExplicitlySpecialized.ql b/cpp/misra/src/rules/RULE-17-8-1/FunctionTemplatesExplicitlySpecialized.ql new file mode 100644 index 0000000000..c7b306946b --- /dev/null +++ b/cpp/misra/src/rules/RULE-17-8-1/FunctionTemplatesExplicitlySpecialized.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/function-templates-explicitly-specialized + * @name RULE-17-8-1: Function templates shall not be explicitly specialized + * @description Function templates shall not be explicitly specialized. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-17-8-1 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.functiontemplatesexplicitlyspecialized.FunctionTemplatesExplicitlySpecialized + +class FunctionTemplatesExplicitlySpecializedQuery extends FunctionTemplatesExplicitlySpecializedSharedQuery +{ + FunctionTemplatesExplicitlySpecializedQuery() { + this = ImportMisra23Package::functionTemplatesExplicitlySpecializedQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-18-1-1/ExceptionObjectHavePointerType.ql b/cpp/misra/src/rules/RULE-18-1-1/ExceptionObjectHavePointerType.ql new file mode 100644 index 0000000000..cbae5c1da4 --- /dev/null +++ b/cpp/misra/src/rules/RULE-18-1-1/ExceptionObjectHavePointerType.ql @@ -0,0 +1,22 @@ +/** + * @id cpp/misra/exception-object-have-pointer-type + * @name RULE-18-1-1: An exception object shall not have pointer type + * @description An exception object shall not have pointer type. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-18-1-1 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.exceptionobjecthavepointertype.ExceptionObjectHavePointerType + +class ExceptionObjectHavePointerTypeQuery extends ExceptionObjectHavePointerTypeSharedQuery { + ExceptionObjectHavePointerTypeQuery() { + this = ImportMisra23Package::exceptionObjectHavePointerTypeQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-18-1-2/EmptyThrowOnlyWithinACatchHandler.ql b/cpp/misra/src/rules/RULE-18-1-2/EmptyThrowOnlyWithinACatchHandler.ql new file mode 100644 index 0000000000..15ca773943 --- /dev/null +++ b/cpp/misra/src/rules/RULE-18-1-2/EmptyThrowOnlyWithinACatchHandler.ql @@ -0,0 +1,22 @@ +/** + * @id cpp/misra/empty-throw-only-within-a-catch-handler + * @name RULE-18-1-2: An empty throw shall only occur within the compound-statement of a catch handler + * @description An empty throw shall only occur within the compound-statement of a catch handler. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-18-1-2 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.emptythrowonlywithinacatchhandler.EmptyThrowOnlyWithinACatchHandler + +class EmptyThrowOnlyWithinACatchHandlerQuery extends EmptyThrowOnlyWithinACatchHandlerSharedQuery { + EmptyThrowOnlyWithinACatchHandlerQuery() { + this = ImportMisra23Package::emptyThrowOnlyWithinACatchHandlerQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-18-5-1/NoexceptFunctionShouldNotPropagateToTheCaller.ql b/cpp/misra/src/rules/RULE-18-5-1/NoexceptFunctionShouldNotPropagateToTheCaller.ql new file mode 100644 index 0000000000..61d8a0ebd4 --- /dev/null +++ b/cpp/misra/src/rules/RULE-18-5-1/NoexceptFunctionShouldNotPropagateToTheCaller.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/noexcept-function-should-not-propagate-to-the-caller + * @name RULE-18-5-1: A noexcept function should not attempt to propagate an exception to the calling function + * @description A noexcept function should not attempt to propagate an exception to the calling + * function. + * @kind path-problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-18-5-1 + * scope/system + * external/misra/enforcement/undecidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.noexceptfunctionshouldnotpropagatetothecaller.NoexceptFunctionShouldNotPropagateToTheCaller + +class NoexceptFunctionShouldNotPropagateToTheCallerQuery extends NoexceptFunctionShouldNotPropagateToTheCallerSharedQuery +{ + NoexceptFunctionShouldNotPropagateToTheCallerQuery() { + this = ImportMisra23Package::noexceptFunctionShouldNotPropagateToTheCallerQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-19-0-2/FunctionLikeMacrosDefined.ql b/cpp/misra/src/rules/RULE-19-0-2/FunctionLikeMacrosDefined.ql new file mode 100644 index 0000000000..d9e4d5a810 --- /dev/null +++ b/cpp/misra/src/rules/RULE-19-0-2/FunctionLikeMacrosDefined.ql @@ -0,0 +1,20 @@ +/** + * @id cpp/misra/function-like-macros-defined + * @name RULE-19-0-2: Function-like macros shall not be defined + * @description Function-like macros shall not be defined. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-19-0-2 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.functionlikemacrosdefined.FunctionLikeMacrosDefined + +class FunctionLikeMacrosDefinedQuery extends FunctionLikeMacrosDefinedSharedQuery { + FunctionLikeMacrosDefinedQuery() { this = ImportMisra23Package::functionLikeMacrosDefinedQuery() } +} diff --git a/cpp/misra/src/rules/RULE-19-3-2/MacroParameterFollowingHash.ql b/cpp/misra/src/rules/RULE-19-3-2/MacroParameterFollowingHash.ql new file mode 100644 index 0000000000..12e95ced04 --- /dev/null +++ b/cpp/misra/src/rules/RULE-19-3-2/MacroParameterFollowingHash.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/macro-parameter-following-hash + * @name RULE-19-3-2: A macro parameter immediately following a # operator shall not be immediately followed by a ## + * @description A macro parameter immediately following a # operator shall not be immediately + * followed by a ## operator. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-19-3-2 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.macroparameterfollowinghash.MacroParameterFollowingHash + +class MacroParameterFollowingHashQuery extends MacroParameterFollowingHashSharedQuery { + MacroParameterFollowingHashQuery() { + this = ImportMisra23Package::macroParameterFollowingHashQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-19-3-3/AMixedUseMacroArgumentSubjectToExpansion.ql b/cpp/misra/src/rules/RULE-19-3-3/AMixedUseMacroArgumentSubjectToExpansion.ql new file mode 100644 index 0000000000..9cb0a7e9c5 --- /dev/null +++ b/cpp/misra/src/rules/RULE-19-3-3/AMixedUseMacroArgumentSubjectToExpansion.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/a-mixed-use-macro-argument-subject-to-expansion + * @name RULE-19-3-3: The argument to a mixed-use macro parameter shall not be subject to further expansion + * @description The argument to a mixed-use macro parameter shall not be subject to further + * expansion. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-19-3-3 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.amixedusemacroargumentsubjecttoexpansion.AMixedUseMacroArgumentSubjectToExpansion + +class AMixedUseMacroArgumentSubjectToExpansionQuery extends AMixedUseMacroArgumentSubjectToExpansionSharedQuery +{ + AMixedUseMacroArgumentSubjectToExpansionQuery() { + this = ImportMisra23Package::aMixedUseMacroArgumentSubjectToExpansionQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-21-10-3/CsignalFacilitiesUsed.ql b/cpp/misra/src/rules/RULE-21-10-3/CsignalFacilitiesUsed.ql new file mode 100644 index 0000000000..3e8c58a8da --- /dev/null +++ b/cpp/misra/src/rules/RULE-21-10-3/CsignalFacilitiesUsed.ql @@ -0,0 +1,22 @@ +/** + * @id cpp/misra/csignal-facilities-used + * @name RULE-21-10-3: The facilities provided by the standard header file shall not be used + * @description Signal handling contains implementation-defined and undefined behaviour. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-21-10-3 + * maintainability + * correctness + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.csignalfunctionsused.CsignalFunctionsUsed + +class CsignalFacilitiesUsedQuery extends CsignalFunctionsUsedSharedQuery { + CsignalFacilitiesUsedQuery() { this = ImportMisra23Package::csignalFacilitiesUsedQuery() } +} diff --git a/cpp/misra/src/rules/RULE-21-10-3/CsignalTypesShallNotBeUsed.ql b/cpp/misra/src/rules/RULE-21-10-3/CsignalTypesShallNotBeUsed.ql new file mode 100644 index 0000000000..0fe1b1dfba --- /dev/null +++ b/cpp/misra/src/rules/RULE-21-10-3/CsignalTypesShallNotBeUsed.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/csignal-types-shall-not-be-used + * @name RULE-21-10-3: The signal-handling types of shall not be used + * @description The types provided by the standard header file shall not be used. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-21-10-3 + * maintainability + * correctness + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.csignaltypesused.CsignalTypesUsed + +class CsignalTypesShallNotBeUsedQuery extends CsignalTypesUsedSharedQuery { + CsignalTypesShallNotBeUsedQuery() { + this = ImportMisra23Package::csignalTypesShallNotBeUsedQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-21-2-1/AtofAtoiAtolAndAtollUsed.ql b/cpp/misra/src/rules/RULE-21-2-1/AtofAtoiAtolAndAtollUsed.ql new file mode 100644 index 0000000000..e5b48d55a7 --- /dev/null +++ b/cpp/misra/src/rules/RULE-21-2-1/AtofAtoiAtolAndAtollUsed.ql @@ -0,0 +1,20 @@ +/** + * @id cpp/misra/atof-atoi-atol-and-atoll-used + * @name RULE-21-2-1: The library functions atof, atoi, atol and atoll from shall not be used + * @description The library functions atof, atoi, atol and atoll from shall not be used. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-21-2-1 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.atofatoiatolandatollused.AtofAtoiAtolAndAtollUsed + +class AtofAtoiAtolAndAtollUsedQuery extends AtofAtoiAtolAndAtollUsedSharedQuery { + AtofAtoiAtolAndAtollUsedQuery() { this = ImportMisra23Package::atofAtoiAtolAndAtollUsedQuery() } +} diff --git a/cpp/misra/src/rules/RULE-21-2-4/MacroOffsetofShallNotBeUsed.ql b/cpp/misra/src/rules/RULE-21-2-4/MacroOffsetofShallNotBeUsed.ql new file mode 100644 index 0000000000..fa6df051ca --- /dev/null +++ b/cpp/misra/src/rules/RULE-21-2-4/MacroOffsetofShallNotBeUsed.ql @@ -0,0 +1,22 @@ +/** + * @id cpp/misra/macro-offsetof-shall-not-be-used + * @name RULE-21-2-4: The macro offsetof shall not be used + * @description The macro offsetof shall not be used. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-21-2-4 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.macrooffsetofused.MacroOffsetofUsed + +class MacroOffsetofShallNotBeUsedQuery extends MacroOffsetofUsedSharedQuery { + MacroOffsetofShallNotBeUsedQuery() { + this = ImportMisra23Package::macroOffsetofShallNotBeUsedQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-21-6-4/GlobalSizedOperatorDeleteShallBeDefined.ql b/cpp/misra/src/rules/RULE-21-6-4/GlobalSizedOperatorDeleteShallBeDefined.ql new file mode 100644 index 0000000000..eb9be3af15 --- /dev/null +++ b/cpp/misra/src/rules/RULE-21-6-4/GlobalSizedOperatorDeleteShallBeDefined.ql @@ -0,0 +1,25 @@ +/** + * @id cpp/misra/global-sized-operator-delete-shall-be-defined + * @name RULE-21-6-4: Sized 'operator delete' must be defined globally if unsized 'operator delete' is defined globally + * @description If a project defines the unsized version of a global operator delete, then the sized + * version shall be defined. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-21-6-4 + * maintainability + * scope/system + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.globalsizedoperatordeletenotdefined.GlobalSizedOperatorDeleteNotDefined + +class GlobalSizedOperatorDeleteShallBeDefinedQuery extends GlobalSizedOperatorDeleteNotDefinedSharedQuery +{ + GlobalSizedOperatorDeleteShallBeDefinedQuery() { + this = ImportMisra23Package::globalSizedOperatorDeleteShallBeDefinedQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-21-6-4/GlobalUnsizedOperatorDeleteShallBeDefined.ql b/cpp/misra/src/rules/RULE-21-6-4/GlobalUnsizedOperatorDeleteShallBeDefined.ql new file mode 100644 index 0000000000..8a80b36e3f --- /dev/null +++ b/cpp/misra/src/rules/RULE-21-6-4/GlobalUnsizedOperatorDeleteShallBeDefined.ql @@ -0,0 +1,25 @@ +/** + * @id cpp/misra/global-unsized-operator-delete-shall-be-defined + * @name RULE-21-6-4: Unsized 'operator delete' must be defined globally if sized 'operator delete' is defined globally + * @description If a project defines the sized version of a global operator delete, then the unsized + * version shall be defined. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-21-6-4 + * maintainability + * scope/system + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.globalunsizedoperatordeletenotdefined.GlobalUnsizedOperatorDeleteNotDefined + +class GlobalUnsizedOperatorDeleteShallBeDefinedQuery extends GlobalUnsizedOperatorDeleteNotDefinedSharedQuery +{ + GlobalUnsizedOperatorDeleteShallBeDefinedQuery() { + this = ImportMisra23Package::globalUnsizedOperatorDeleteShallBeDefinedQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-26-3-1/VectorShouldNotBeSpecializedWithBool.ql b/cpp/misra/src/rules/RULE-26-3-1/VectorShouldNotBeSpecializedWithBool.ql new file mode 100644 index 0000000000..90037b5f29 --- /dev/null +++ b/cpp/misra/src/rules/RULE-26-3-1/VectorShouldNotBeSpecializedWithBool.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/vector-should-not-be-specialized-with-bool + * @name RULE-26-3-1: std::vector should not be specialized with bool + * @description std::vector should not be specialized with bool. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-26-3-1 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.vectorshouldnotbespecializedwithbool.VectorShouldNotBeSpecializedWithBool + +class VectorShouldNotBeSpecializedWithBoolQuery extends VectorShouldNotBeSpecializedWithBoolSharedQuery +{ + VectorShouldNotBeSpecializedWithBoolQuery() { + this = ImportMisra23Package::vectorShouldNotBeSpecializedWithBoolQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-28-6-2/ForwardingReferencesAndForwardNotUsedTogether.ql b/cpp/misra/src/rules/RULE-28-6-2/ForwardingReferencesAndForwardNotUsedTogether.ql new file mode 100644 index 0000000000..dc407512cc --- /dev/null +++ b/cpp/misra/src/rules/RULE-28-6-2/ForwardingReferencesAndForwardNotUsedTogether.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/forwarding-references-and-forward-not-used-together + * @name RULE-28-6-2: Forwarding references and std::forward shall be used together + * @description Forwarding references and std::forward shall be used together. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-28-6-2 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.forwardingreferencesandforwardnotusedtogether.ForwardingReferencesAndForwardNotUsedTogether + +class ForwardingReferencesAndForwardNotUsedTogetherQuery extends ForwardingReferencesAndForwardNotUsedTogetherSharedQuery +{ + ForwardingReferencesAndForwardNotUsedTogetherQuery() { + this = ImportMisra23Package::forwardingReferencesAndForwardNotUsedTogetherQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-30-0-1/CstdioFunctionsShallNotBeUsed.ql b/cpp/misra/src/rules/RULE-30-0-1/CstdioFunctionsShallNotBeUsed.ql new file mode 100644 index 0000000000..58c8a500f4 --- /dev/null +++ b/cpp/misra/src/rules/RULE-30-0-1/CstdioFunctionsShallNotBeUsed.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/cstdio-functions-shall-not-be-used + * @name RULE-30-0-1: The stream input/output library functions shall not be used + * @description The C Library input/output functions shall not be used. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-30-0-1 + * maintainability + * correctness + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.cstdiofunctionsused.CstdioFunctionsUsed + +class CstdioFunctionsShallNotBeUsedQuery extends CstdioFunctionsUsedSharedQuery { + CstdioFunctionsShallNotBeUsedQuery() { + this = ImportMisra23Package::cstdioFunctionsShallNotBeUsedQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-30-0-1/CstdioMacrosShallNotBeUsed.ql b/cpp/misra/src/rules/RULE-30-0-1/CstdioMacrosShallNotBeUsed.ql new file mode 100644 index 0000000000..8f0b9438e3 --- /dev/null +++ b/cpp/misra/src/rules/RULE-30-0-1/CstdioMacrosShallNotBeUsed.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/cstdio-macros-shall-not-be-used + * @name RULE-30-0-1: The stream input/output library macros shall not be used + * @description The C Library input/output functions shall not be used. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-30-0-1 + * maintainability + * correctness + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.cstdiomacrosused.CstdioMacrosUsed + +class CstdioMacrosShallNotBeUsedQuery extends CstdioMacrosUsedSharedQuery { + CstdioMacrosShallNotBeUsedQuery() { + this = ImportMisra23Package::cstdioMacrosShallNotBeUsedQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-30-0-1/CstdioTypesShallNotBeUsed.ql b/cpp/misra/src/rules/RULE-30-0-1/CstdioTypesShallNotBeUsed.ql new file mode 100644 index 0000000000..6966c85068 --- /dev/null +++ b/cpp/misra/src/rules/RULE-30-0-1/CstdioTypesShallNotBeUsed.ql @@ -0,0 +1,22 @@ +/** + * @id cpp/misra/cstdio-types-shall-not-be-used + * @name RULE-30-0-1: The stream input/output library types shall not be used + * @description The C Library input/output functions shall not be used. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-30-0-1 + * maintainability + * correctness + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.cstdiotypesused.CstdioTypesUsed + +class CstdioTypesShallNotBeUsedQuery extends CstdioTypesUsedSharedQuery { + CstdioTypesShallNotBeUsedQuery() { this = ImportMisra23Package::cstdioTypesShallNotBeUsedQuery() } +} diff --git a/cpp/misra/src/rules/RULE-5-13-1/BackslashCharacterMisuse.ql b/cpp/misra/src/rules/RULE-5-13-1/BackslashCharacterMisuse.ql new file mode 100644 index 0000000000..fde97e062c --- /dev/null +++ b/cpp/misra/src/rules/RULE-5-13-1/BackslashCharacterMisuse.ql @@ -0,0 +1,21 @@ +/** + * @id cpp/misra/backslash-character-misuse + * @name RULE-5-13-1: In character literals and non-raw string literals, \ shall only be used to form a defined escape + * @description In character literals and non-raw string literals, \ shall only be used to form a + * defined escape sequence or universal character name. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-5-13-1 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.backslashcharactermisuse.BackslashCharacterMisuse + +class BackslashCharacterMisuseQuery extends BackslashCharacterMisuseSharedQuery { + BackslashCharacterMisuseQuery() { this = ImportMisra23Package::backslashCharacterMisuseQuery() } +} diff --git a/cpp/misra/src/rules/RULE-5-13-2/NonTerminatedEscapeSequences.ql b/cpp/misra/src/rules/RULE-5-13-2/NonTerminatedEscapeSequences.ql new file mode 100644 index 0000000000..d21f1ef1f9 --- /dev/null +++ b/cpp/misra/src/rules/RULE-5-13-2/NonTerminatedEscapeSequences.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/non-terminated-escape-sequences + * @name RULE-5-13-2: Octal escape sequences, hexadecimal escape sequences, and universal character names shall be + * @description Octal escape sequences, hexadecimal escape sequences, and universal character names + * shall be terminated. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-5-13-2 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.nonterminatedescapesequences.NonTerminatedEscapeSequences + +class NonTerminatedEscapeSequencesQuery extends NonTerminatedEscapeSequencesSharedQuery { + NonTerminatedEscapeSequencesQuery() { + this = ImportMisra23Package::nonTerminatedEscapeSequencesQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-5-13-3/OctalConstantsUsed.ql b/cpp/misra/src/rules/RULE-5-13-3/OctalConstantsUsed.ql new file mode 100644 index 0000000000..38bb96faac --- /dev/null +++ b/cpp/misra/src/rules/RULE-5-13-3/OctalConstantsUsed.ql @@ -0,0 +1,20 @@ +/** + * @id cpp/misra/octal-constants-used + * @name RULE-5-13-3: Octal constants shall not be used + * @description Octal constants shall not be used. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-5-13-3 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.useofnonzerooctalliteral.UseOfNonZeroOctalLiteral + +class OctalConstantsUsedQuery extends UseOfNonZeroOctalLiteralSharedQuery { + OctalConstantsUsedQuery() { this = ImportMisra23Package::octalConstantsUsedQuery() } +} diff --git a/cpp/misra/src/rules/RULE-5-13-4/UnsignedIntegerLiteralsNotAppropriatelySuffixed.ql b/cpp/misra/src/rules/RULE-5-13-4/UnsignedIntegerLiteralsNotAppropriatelySuffixed.ql new file mode 100644 index 0000000000..b3802cf0be --- /dev/null +++ b/cpp/misra/src/rules/RULE-5-13-4/UnsignedIntegerLiteralsNotAppropriatelySuffixed.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/unsigned-integer-literals-not-appropriately-suffixed + * @name RULE-5-13-4: Unsigned integer literals shall be appropriately suffixed + * @description Unsigned integer literals shall be appropriately suffixed. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-5-13-4 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.unsignedintegerliteralsnotappropriatelysuffixed.UnsignedIntegerLiteralsNotAppropriatelySuffixed + +class UnsignedIntegerLiteralsNotAppropriatelySuffixedQuery extends UnsignedIntegerLiteralsNotAppropriatelySuffixedSharedQuery +{ + UnsignedIntegerLiteralsNotAppropriatelySuffixedQuery() { + this = ImportMisra23Package::unsignedIntegerLiteralsNotAppropriatelySuffixedQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-5-13-5/LowercaseLStartsInLiteralSuffix.ql b/cpp/misra/src/rules/RULE-5-13-5/LowercaseLStartsInLiteralSuffix.ql new file mode 100644 index 0000000000..a47c0ded0c --- /dev/null +++ b/cpp/misra/src/rules/RULE-5-13-5/LowercaseLStartsInLiteralSuffix.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/lowercase-l-starts-in-literal-suffix + * @name RULE-5-13-5: The lowercase form of L shall not be used as the first character in a literal suffix + * @description The lowercase form of L shall not be used as the first character in a literal + * suffix. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-5-13-5 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.lowercaselstartsinliteralsuffix.LowercaseLStartsInLiteralSuffix + +class LowercaseLStartsInLiteralSuffixQuery extends LowercaseLStartsInLiteralSuffixSharedQuery { + LowercaseLStartsInLiteralSuffixQuery() { + this = ImportMisra23Package::lowercaseLStartsInLiteralSuffixQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-5-7-1/CharacterSequenceUsedWithinACStyleComment.ql b/cpp/misra/src/rules/RULE-5-7-1/CharacterSequenceUsedWithinACStyleComment.ql new file mode 100644 index 0000000000..1bdb42de77 --- /dev/null +++ b/cpp/misra/src/rules/RULE-5-7-1/CharacterSequenceUsedWithinACStyleComment.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/character-sequence-used-within-ac-style-comment + * @name RULE-5-7-1: The character sequence /* shall not be used within a C-style comment + * @description The character sequence /* shall not be used within a C-style comment. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-5-7-1 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.charactersequenceusedwithinacstylecomment.CharacterSequenceUsedWithinACStyleComment + +class CharacterSequenceUsedWithinACStyleCommentQuery extends CharacterSequenceUsedWithinACStyleCommentSharedQuery +{ + CharacterSequenceUsedWithinACStyleCommentQuery() { + this = ImportMisra23Package::characterSequenceUsedWithinACStyleCommentQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-5-7-3/LineSplicingUsedInComments.ql b/cpp/misra/src/rules/RULE-5-7-3/LineSplicingUsedInComments.ql new file mode 100644 index 0000000000..ae58fdcda9 --- /dev/null +++ b/cpp/misra/src/rules/RULE-5-7-3/LineSplicingUsedInComments.ql @@ -0,0 +1,22 @@ +/** + * @id cpp/misra/line-splicing-used-in-comments + * @name RULE-5-7-3: Line-splicing shall not be used in // comments + * @description Line-splicing shall not be used in // comments. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-5-7-3 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.linesplicingusedincomments.LineSplicingUsedInComments + +class LineSplicingUsedInCommentsQuery extends LineSplicingUsedInCommentsSharedQuery { + LineSplicingUsedInCommentsQuery() { + this = ImportMisra23Package::lineSplicingUsedInCommentsQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-6-0-3/GlobalNamespaceDeclarations.ql b/cpp/misra/src/rules/RULE-6-0-3/GlobalNamespaceDeclarations.ql new file mode 100644 index 0000000000..addd8f2eab --- /dev/null +++ b/cpp/misra/src/rules/RULE-6-0-3/GlobalNamespaceDeclarations.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/global-namespace-declarations + * @name RULE-6-0-3: The only declarations in the global namespace should be main, namespace declarations and extern "C" + * @description The only declarations in the global namespace should be main, namespace declarations + * and extern "C" declarations. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-6-0-3 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.globalnamespacedeclarations.GlobalNamespaceDeclarations + +class GlobalNamespaceDeclarationsQuery extends GlobalNamespaceDeclarationsSharedQuery { + GlobalNamespaceDeclarationsQuery() { + this = ImportMisra23Package::globalNamespaceDeclarationsQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-6-0-4/NonGlobalFunctionMain.ql b/cpp/misra/src/rules/RULE-6-0-4/NonGlobalFunctionMain.ql new file mode 100644 index 0000000000..f9eb9e1d44 --- /dev/null +++ b/cpp/misra/src/rules/RULE-6-0-4/NonGlobalFunctionMain.ql @@ -0,0 +1,21 @@ +/** + * @id cpp/misra/non-global-function-main + * @name RULE-6-0-4: The identifier main shall not be used for a function other than the global function main + * @description The identifier main shall not be used for a function other than the global function + * main. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-6-0-4 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.nonglobalfunctionmain.NonGlobalFunctionMain + +class NonGlobalFunctionMainQuery extends NonGlobalFunctionMainSharedQuery { + NonGlobalFunctionMainQuery() { this = ImportMisra23Package::nonGlobalFunctionMainQuery() } +} diff --git a/cpp/misra/src/rules/RULE-6-4-2/DefinitionShallBeConsideredForUnqualifiedLookup.ql b/cpp/misra/src/rules/RULE-6-4-2/DefinitionShallBeConsideredForUnqualifiedLookup.ql new file mode 100644 index 0000000000..faa0857d62 --- /dev/null +++ b/cpp/misra/src/rules/RULE-6-4-2/DefinitionShallBeConsideredForUnqualifiedLookup.ql @@ -0,0 +1,26 @@ +/** + * @id cpp/misra/definition-shall-be-considered-for-unqualified-lookup + * @name RULE-6-4-2: Using declaration followed by new definition + * @description A using declaration that makes a symbol available for unqualified lookup does not + * included definitions defined after the using declaration which can result in + * unexpected behavior. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-6-4-2 + * correctness + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.definitionnotconsideredforunqualifiedlookup.DefinitionNotConsideredForUnqualifiedLookup + +class DefinitionShallBeConsideredForUnqualifiedLookupQuery extends DefinitionNotConsideredForUnqualifiedLookupSharedQuery +{ + DefinitionShallBeConsideredForUnqualifiedLookupQuery() { + this = ImportMisra23Package::definitionShallBeConsideredForUnqualifiedLookupQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-6-4-2/InheritedNonOverridableMemberFunction.ql b/cpp/misra/src/rules/RULE-6-4-2/InheritedNonOverridableMemberFunction.ql new file mode 100644 index 0000000000..b81f2a2c4f --- /dev/null +++ b/cpp/misra/src/rules/RULE-6-4-2/InheritedNonOverridableMemberFunction.ql @@ -0,0 +1,25 @@ +/** + * @id cpp/misra/inherited-non-overridable-member-function + * @name RULE-6-4-2: Member function hides inherited member function + * @description A non-overriding member function definition that hides an inherited member function + * can result in unexpected behavior. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-6-4-2 + * correctness + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.hiddeninheritednonoverridablememberfunction.HiddenInheritedNonOverridableMemberFunction + +class InheritedNonOverridableMemberFunctionQuery extends HiddenInheritedNonOverridableMemberFunctionSharedQuery +{ + InheritedNonOverridableMemberFunctionQuery() { + this = ImportMisra23Package::inheritedNonOverridableMemberFunctionQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-6-4-2/InheritedOverridableMemberFunction.ql b/cpp/misra/src/rules/RULE-6-4-2/InheritedOverridableMemberFunction.ql new file mode 100644 index 0000000000..9fa94560f4 --- /dev/null +++ b/cpp/misra/src/rules/RULE-6-4-2/InheritedOverridableMemberFunction.ql @@ -0,0 +1,25 @@ +/** + * @id cpp/misra/inherited-overridable-member-function + * @name RULE-6-4-2: Member function hides inherited member function + * @description An overriding member function definition thats hides an overload of the overridden + * inherited member function can result in unexpected behavior. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-6-4-2 + * correctness + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.hiddeninheritedoverridablememberfunction.HiddenInheritedOverridableMemberFunction + +class InheritedOverridableMemberFunctionQuery extends HiddenInheritedOverridableMemberFunctionSharedQuery +{ + InheritedOverridableMemberFunctionQuery() { + this = ImportMisra23Package::inheritedOverridableMemberFunctionQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-6-4-3/NameShallBeReferredUsingAQualifiedIdOrThis.ql b/cpp/misra/src/rules/RULE-6-4-3/NameShallBeReferredUsingAQualifiedIdOrThis.ql new file mode 100644 index 0000000000..3d43b4134a --- /dev/null +++ b/cpp/misra/src/rules/RULE-6-4-3/NameShallBeReferredUsingAQualifiedIdOrThis.ql @@ -0,0 +1,26 @@ +/** + * @id cpp/misra/name-shall-be-referred-using-a-qualified-id-or-this + * @name RULE-6-4-3: In a class template with a dependent base, any name that may be found in that dependent base shall shall be referred to using a qualified-id or this-> + * @description Not using a qualified-id or `this->` syntax for identifiers used in a class template + * makes the code more difficult to understand. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-6-4-3 + * maintainability + * readability + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.namenotreferredusingaqualifiedidorthis.NameNotReferredUsingAQualifiedIdOrThis + +class NameShallBeReferredUsingAQualifiedIdOrThisQuery extends NameNotReferredUsingAQualifiedIdOrThisSharedQuery +{ + NameShallBeReferredUsingAQualifiedIdOrThisQuery() { + this = ImportMisra23Package::nameShallBeReferredUsingAQualifiedIdOrThisQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-6-4-3/NameShallBeReferredUsingAQualifiedIdOrThisAudit.ql b/cpp/misra/src/rules/RULE-6-4-3/NameShallBeReferredUsingAQualifiedIdOrThisAudit.ql new file mode 100644 index 0000000000..df2180fc7b --- /dev/null +++ b/cpp/misra/src/rules/RULE-6-4-3/NameShallBeReferredUsingAQualifiedIdOrThisAudit.ql @@ -0,0 +1,26 @@ +/** + * @id cpp/misra/name-shall-be-referred-using-a-qualified-id-or-this-audit + * @name RULE-6-4-3: (Audit) In a class template with a dependent base, any name that may be found in that dependent base shall shall be referred to using a qualified-id or this-> + * @description Not using a qualified-id or `this->` syntax for identifiers used in a class template + * makes the code more difficult to understand. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/rule-6-4-3 + * maintainability + * readability + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.namenotreferredusingaqualifiedidorthisaudit.NameNotReferredUsingAQualifiedIdOrThisAudit + +class NameShallBeReferredUsingAQualifiedIdOrThisAuditQuery extends NameNotReferredUsingAQualifiedIdOrThisAuditSharedQuery +{ + NameShallBeReferredUsingAQualifiedIdOrThisAuditQuery() { + this = ImportMisra23Package::nameShallBeReferredUsingAQualifiedIdOrThisAuditQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-6-8-2/ReturnReferenceOrPointerToAutomaticLocalVariable.ql b/cpp/misra/src/rules/RULE-6-8-2/ReturnReferenceOrPointerToAutomaticLocalVariable.ql new file mode 100644 index 0000000000..bcf026cbba --- /dev/null +++ b/cpp/misra/src/rules/RULE-6-8-2/ReturnReferenceOrPointerToAutomaticLocalVariable.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/return-reference-or-pointer-to-automatic-local-variable + * @name RULE-6-8-2: A function must not return a reference or a pointer to a local variable with automatic storage + * @description A function must not return a reference or a pointer to a local variable with + * automatic storage duration. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-6-8-2 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/mandatory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.returnreferenceorpointertoautomaticlocalvariable.ReturnReferenceOrPointerToAutomaticLocalVariable + +class ReturnReferenceOrPointerToAutomaticLocalVariableQuery extends ReturnReferenceOrPointerToAutomaticLocalVariableSharedQuery +{ + ReturnReferenceOrPointerToAutomaticLocalVariableQuery() { + this = ImportMisra23Package::returnReferenceOrPointerToAutomaticLocalVariableQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-7-11-1/NullptrNotTheOnlyFormOfTheNullPointerConstant.ql b/cpp/misra/src/rules/RULE-7-11-1/NullptrNotTheOnlyFormOfTheNullPointerConstant.ql new file mode 100644 index 0000000000..a0dfc63799 --- /dev/null +++ b/cpp/misra/src/rules/RULE-7-11-1/NullptrNotTheOnlyFormOfTheNullPointerConstant.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/nullptr-not-the-only-form-of-the-null-pointer-constant + * @name RULE-7-11-1: nullptr shall be the only form of the null-pointer-constant + * @description nullptr shall be the only form of the null-pointer-constant. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-7-11-1 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.nullptrnottheonlyformofthenullpointerconstant.NullptrNotTheOnlyFormOfTheNullPointerConstant + +class NullptrNotTheOnlyFormOfTheNullPointerConstantQuery extends NullptrNotTheOnlyFormOfTheNullPointerConstantSharedQuery +{ + NullptrNotTheOnlyFormOfTheNullPointerConstantQuery() { + this = ImportMisra23Package::nullptrNotTheOnlyFormOfTheNullPointerConstantQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-7-11-2/ArrayPassedAsFunctionArgumentDecayToAPointer.ql b/cpp/misra/src/rules/RULE-7-11-2/ArrayPassedAsFunctionArgumentDecayToAPointer.ql new file mode 100644 index 0000000000..fed33c33de --- /dev/null +++ b/cpp/misra/src/rules/RULE-7-11-2/ArrayPassedAsFunctionArgumentDecayToAPointer.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/array-passed-as-function-argument-decay-to-a-pointer + * @name RULE-7-11-2: An array passed as a function argument shall not decay to a pointer + * @description An array passed as a function argument shall not decay to a pointer. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-7-11-2 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.arraypassedasfunctionargumentdecaytoapointer.ArrayPassedAsFunctionArgumentDecayToAPointer + +class ArrayPassedAsFunctionArgumentDecayToAPointerQuery extends ArrayPassedAsFunctionArgumentDecayToAPointerSharedQuery +{ + ArrayPassedAsFunctionArgumentDecayToAPointerQuery() { + this = ImportMisra23Package::arrayPassedAsFunctionArgumentDecayToAPointerQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-8-18-2/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql b/cpp/misra/src/rules/RULE-8-18-2/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql new file mode 100644 index 0000000000..6c4b1a82ad --- /dev/null +++ b/cpp/misra/src/rules/RULE-8-18-2/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/result-of-an-assignment-operator-should-not-be-used + * @name RULE-8-18-2: The result of an assignment operator should not be used + * @description The result of an assignment operator should not be used. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-8-18-2 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.resultofanassignmentoperatorshouldnotbeused.ResultOfAnAssignmentOperatorShouldNotBeUsed + +class ResultOfAnAssignmentOperatorShouldNotBeUsedQuery extends ResultOfAnAssignmentOperatorShouldNotBeUsedSharedQuery +{ + ResultOfAnAssignmentOperatorShouldNotBeUsedQuery() { + this = ImportMisra23Package::resultOfAnAssignmentOperatorShouldNotBeUsedQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-8-19-1/CommaOperatorShouldNotBeUsed.ql b/cpp/misra/src/rules/RULE-8-19-1/CommaOperatorShouldNotBeUsed.ql new file mode 100644 index 0000000000..df5be50dc0 --- /dev/null +++ b/cpp/misra/src/rules/RULE-8-19-1/CommaOperatorShouldNotBeUsed.ql @@ -0,0 +1,22 @@ +/** + * @id cpp/misra/comma-operator-should-not-be-used + * @name RULE-8-19-1: The comma operator should not be used + * @description The comma operator should not be used. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-8-19-1 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.commaoperatorused.CommaOperatorUsed + +class CommaOperatorShouldNotBeUsedQuery extends CommaOperatorUsedSharedQuery { + CommaOperatorShouldNotBeUsedQuery() { + this = ImportMisra23Package::commaOperatorShouldNotBeUsedQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-8-2-10/FunctionsCallThemselvesEitherDirectlyOrIndirectly.ql b/cpp/misra/src/rules/RULE-8-2-10/FunctionsCallThemselvesEitherDirectlyOrIndirectly.ql new file mode 100644 index 0000000000..ff0f397572 --- /dev/null +++ b/cpp/misra/src/rules/RULE-8-2-10/FunctionsCallThemselvesEitherDirectlyOrIndirectly.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/functions-call-themselves-either-directly-or-indirectly + * @name RULE-8-2-10: Functions shall not call themselves, either directly or indirectly + * @description Functions shall not call themselves, either directly or indirectly. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-8-2-10 + * scope/system + * external/misra/enforcement/undecidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.functionscallthemselveseitherdirectlyorindirectly.FunctionsCallThemselvesEitherDirectlyOrIndirectly + +class FunctionsCallThemselvesEitherDirectlyOrIndirectlyQuery extends FunctionsCallThemselvesEitherDirectlyOrIndirectlySharedQuery +{ + FunctionsCallThemselvesEitherDirectlyOrIndirectlyQuery() { + this = ImportMisra23Package::functionsCallThemselvesEitherDirectlyOrIndirectlyQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-8-2-4/CastsBetweenAPointerToFunctionAndAnyOtherType.ql b/cpp/misra/src/rules/RULE-8-2-4/CastsBetweenAPointerToFunctionAndAnyOtherType.ql new file mode 100644 index 0000000000..37c258b722 --- /dev/null +++ b/cpp/misra/src/rules/RULE-8-2-4/CastsBetweenAPointerToFunctionAndAnyOtherType.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/casts-between-a-pointer-to-function-and-any-other-type + * @name RULE-8-2-4: Casts shall not be performed between a pointer to function and any other type + * @description Casts shall not be performed between a pointer to function and any other type. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-8-2-4 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.castsbetweenapointertofunctionandanyothertype.CastsBetweenAPointerToFunctionAndAnyOtherType + +class CastsBetweenAPointerToFunctionAndAnyOtherTypeQuery extends CastsBetweenAPointerToFunctionAndAnyOtherTypeSharedQuery +{ + CastsBetweenAPointerToFunctionAndAnyOtherTypeQuery() { + this = ImportMisra23Package::castsBetweenAPointerToFunctionAndAnyOtherTypeQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-8-2-5/ReinterpretCastShallNotBeUsed.ql b/cpp/misra/src/rules/RULE-8-2-5/ReinterpretCastShallNotBeUsed.ql new file mode 100644 index 0000000000..685ebb7efd --- /dev/null +++ b/cpp/misra/src/rules/RULE-8-2-5/ReinterpretCastShallNotBeUsed.ql @@ -0,0 +1,22 @@ +/** + * @id cpp/misra/reinterpret-cast-shall-not-be-used + * @name RULE-8-2-5: reinterpret_cast shall not be used + * @description reinterpret_cast shall not be used. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-8-2-5 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.reinterpretcastused.ReinterpretCastUsed + +class ReinterpretCastShallNotBeUsedQuery extends ReinterpretCastUsedSharedQuery { + ReinterpretCastShallNotBeUsedQuery() { + this = ImportMisra23Package::reinterpretCastShallNotBeUsedQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-8-20-1/UnsignedOperationWithConstantOperandsWraps.ql b/cpp/misra/src/rules/RULE-8-20-1/UnsignedOperationWithConstantOperandsWraps.ql new file mode 100644 index 0000000000..e62acb8257 --- /dev/null +++ b/cpp/misra/src/rules/RULE-8-20-1/UnsignedOperationWithConstantOperandsWraps.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/unsigned-operation-with-constant-operands-wraps + * @name RULE-8-20-1: An unsigned arithmetic operation with constant operands should not wrap + * @description An unsigned arithmetic operation with constant operands should not wrap. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-8-20-1 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.unsignedoperationwithconstantoperandswraps.UnsignedOperationWithConstantOperandsWraps + +class UnsignedOperationWithConstantOperandsWrapsQuery extends UnsignedOperationWithConstantOperandsWrapsSharedQuery +{ + UnsignedOperationWithConstantOperandsWrapsQuery() { + this = ImportMisra23Package::unsignedOperationWithConstantOperandsWrapsQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-8-3-1/BuiltInUnaryOperatorAppliedToUnsignedExpression.ql b/cpp/misra/src/rules/RULE-8-3-1/BuiltInUnaryOperatorAppliedToUnsignedExpression.ql new file mode 100644 index 0000000000..c847348d1c --- /dev/null +++ b/cpp/misra/src/rules/RULE-8-3-1/BuiltInUnaryOperatorAppliedToUnsignedExpression.ql @@ -0,0 +1,24 @@ +/** + * @id cpp/misra/built-in-unary-operator-applied-to-unsigned-expression + * @name RULE-8-3-1: The built-in unary - operator should not be applied to an expression of unsigned type + * @description The built-in unary - operator should not be applied to an expression of unsigned + * type. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-8-3-1 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.builtinunaryoperatorappliedtounsignedexpression.BuiltInUnaryOperatorAppliedToUnsignedExpression + +class BuiltInUnaryOperatorAppliedToUnsignedExpressionQuery extends BuiltInUnaryOperatorAppliedToUnsignedExpressionSharedQuery +{ + BuiltInUnaryOperatorAppliedToUnsignedExpressionQuery() { + this = ImportMisra23Package::builtInUnaryOperatorAppliedToUnsignedExpressionQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-9-3-1/LoopBodyCompoundCondition.ql b/cpp/misra/src/rules/RULE-9-3-1/LoopBodyCompoundCondition.ql new file mode 100644 index 0000000000..b87009d8c1 --- /dev/null +++ b/cpp/misra/src/rules/RULE-9-3-1/LoopBodyCompoundCondition.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/loop-body-compound-condition + * @name RULE-9-3-1: The statement forming the body of a loop shall be a compound statement + * @description If the body of a loop is not enclosed in braces, then this can lead to incorrect + * execution, and hard for developers to maintain. + * @kind problem + * @precision very-high + * @problem.severity recommendation + * @tags external/misra/id/rule-9-3-1 + * maintainability + * readability + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.loopcompoundcondition.LoopCompoundCondition + +class LoopBodyCompoundConditionQuery extends LoopCompoundConditionSharedQuery { + LoopBodyCompoundConditionQuery() { this = ImportMisra23Package::loopBodyCompoundConditionQuery() } +} diff --git a/cpp/misra/src/rules/RULE-9-3-1/SwitchBodyCompoundCondition.ql b/cpp/misra/src/rules/RULE-9-3-1/SwitchBodyCompoundCondition.ql new file mode 100644 index 0000000000..7bee3c027e --- /dev/null +++ b/cpp/misra/src/rules/RULE-9-3-1/SwitchBodyCompoundCondition.ql @@ -0,0 +1,25 @@ +/** + * @id cpp/misra/switch-body-compound-condition + * @name RULE-9-3-1: The statement forming the body of a switch shall be a compound statement + * @description If the body of a switch is not enclosed in braces, then this can lead to incorrect + * execution, and hard for developers to maintain. + * @kind problem + * @precision very-high + * @problem.severity recommendation + * @tags external/misra/id/rule-9-3-1 + * maintainability + * readability + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.switchcompoundcondition.SwitchCompoundCondition + +class SwitchBodyCompoundConditionQuery extends SwitchCompoundConditionSharedQuery { + SwitchBodyCompoundConditionQuery() { + this = ImportMisra23Package::switchBodyCompoundConditionQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-9-6-1/GotoStatementShouldNotBeUsed.ql b/cpp/misra/src/rules/RULE-9-6-1/GotoStatementShouldNotBeUsed.ql new file mode 100644 index 0000000000..1751aa3c37 --- /dev/null +++ b/cpp/misra/src/rules/RULE-9-6-1/GotoStatementShouldNotBeUsed.ql @@ -0,0 +1,22 @@ +/** + * @id cpp/misra/goto-statement-should-not-be-used + * @name RULE-9-6-1: The goto statement should not be used + * @description The goto statement should not be used. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-9-6-1 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/advisory + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.gotostatementshouldnotbeused.GotoStatementShouldNotBeUsed + +class GotoStatementShouldNotBeUsedQuery extends GotoStatementShouldNotBeUsedSharedQuery { + GotoStatementShouldNotBeUsedQuery() { + this = ImportMisra23Package::gotoStatementShouldNotBeUsedQuery() + } +} diff --git a/cpp/misra/src/rules/RULE-9-6-2/GotoReferenceALabelInSurroundingBlock.ql b/cpp/misra/src/rules/RULE-9-6-2/GotoReferenceALabelInSurroundingBlock.ql new file mode 100644 index 0000000000..6e11a73f7f --- /dev/null +++ b/cpp/misra/src/rules/RULE-9-6-2/GotoReferenceALabelInSurroundingBlock.ql @@ -0,0 +1,23 @@ +/** + * @id cpp/misra/goto-reference-a-label-in-surrounding-block + * @name RULE-9-6-2: A goto statement shall reference a label in a surrounding block + * @description A goto statement shall reference a label in a surrounding block. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-9-6-2 + * scope/single-translation-unit + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.gotoreferencealabelinsurroundingblock.GotoReferenceALabelInSurroundingBlock + +class GotoReferenceALabelInSurroundingBlockQuery extends GotoReferenceALabelInSurroundingBlockSharedQuery +{ + GotoReferenceALabelInSurroundingBlockQuery() { + this = ImportMisra23Package::gotoReferenceALabelInSurroundingBlockQuery() + } +} diff --git a/cpp/misra/test/rules/DIR-15-8-1/CopyAndMoveAssignmentsShallHandleSelfAssignment.testref b/cpp/misra/test/rules/DIR-15-8-1/CopyAndMoveAssignmentsShallHandleSelfAssignment.testref new file mode 100644 index 0000000000..65fc614121 --- /dev/null +++ b/cpp/misra/test/rules/DIR-15-8-1/CopyAndMoveAssignmentsShallHandleSelfAssignment.testref @@ -0,0 +1 @@ +cpp/common/test/rules/copyandmoveassignmentsshallhandleselfassignment/CopyAndMoveAssignmentsShallHandleSelfAssignment.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-10-0-1/UseSingleGlobalOrMemberDeclarators.testref b/cpp/misra/test/rules/RULE-10-0-1/UseSingleGlobalOrMemberDeclarators.testref new file mode 100644 index 0000000000..434cb47456 --- /dev/null +++ b/cpp/misra/test/rules/RULE-10-0-1/UseSingleGlobalOrMemberDeclarators.testref @@ -0,0 +1 @@ +cpp/common/test/rules/multipleglobalormemberdeclarators/MultipleGlobalOrMemberDeclarators.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-10-0-1/UseSingleLocalDeclarators.testref b/cpp/misra/test/rules/RULE-10-0-1/UseSingleLocalDeclarators.testref new file mode 100644 index 0000000000..be7c9ac352 --- /dev/null +++ b/cpp/misra/test/rules/RULE-10-0-1/UseSingleLocalDeclarators.testref @@ -0,0 +1 @@ +cpp/common/test/rules/multiplelocaldeclarators/MultipleLocalDeclarators.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-10-2-1/EnumerationNotDefinedWithAnExplicitUnderlyingType.testref b/cpp/misra/test/rules/RULE-10-2-1/EnumerationNotDefinedWithAnExplicitUnderlyingType.testref new file mode 100644 index 0000000000..d7a73fd488 --- /dev/null +++ b/cpp/misra/test/rules/RULE-10-2-1/EnumerationNotDefinedWithAnExplicitUnderlyingType.testref @@ -0,0 +1 @@ +cpp/common/test/rules/enumerationnotdefinedwithanexplicitunderlyingtype/EnumerationNotDefinedWithAnExplicitUnderlyingType.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-10-4-1/AsmDeclarationShallNotBeUsed.testref b/cpp/misra/test/rules/RULE-10-4-1/AsmDeclarationShallNotBeUsed.testref new file mode 100644 index 0000000000..f643f6a9c7 --- /dev/null +++ b/cpp/misra/test/rules/RULE-10-4-1/AsmDeclarationShallNotBeUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/asmdeclarationused/AsmDeclarationUsed.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-11-6-3/NonUniqueEnumerationConstant.testref b/cpp/misra/test/rules/RULE-11-6-3/NonUniqueEnumerationConstant.testref new file mode 100644 index 0000000000..6606e891ab --- /dev/null +++ b/cpp/misra/test/rules/RULE-11-6-3/NonUniqueEnumerationConstant.testref @@ -0,0 +1 @@ +cpp/common/test/rules/nonuniqueenumerationconstant/NonUniqueEnumerationConstant.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-12-2-2/BitFieldShallHaveAnAppropriateType.testref b/cpp/misra/test/rules/RULE-12-2-2/BitFieldShallHaveAnAppropriateType.testref new file mode 100644 index 0000000000..9e4a9a69c7 --- /dev/null +++ b/cpp/misra/test/rules/RULE-12-2-2/BitFieldShallHaveAnAppropriateType.testref @@ -0,0 +1 @@ +cpp/common/test/rules/bitfieldshallhaveanappropriatetype/BitFieldShallHaveAnAppropriateType.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-12-2-3/SignedIntegerNamedBitFieldHaveALengthOfOneBit.testref b/cpp/misra/test/rules/RULE-12-2-3/SignedIntegerNamedBitFieldHaveALengthOfOneBit.testref new file mode 100644 index 0000000000..5dd7991a37 --- /dev/null +++ b/cpp/misra/test/rules/RULE-12-2-3/SignedIntegerNamedBitFieldHaveALengthOfOneBit.testref @@ -0,0 +1 @@ +cpp/common/test/rules/namedbitfieldswithsignedintegertype/NamedBitFieldsWithSignedIntegerType.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-13-1-2/VirtualAndNonVirtualClassInTheHierarchy.testref b/cpp/misra/test/rules/RULE-13-1-2/VirtualAndNonVirtualClassInTheHierarchy.testref new file mode 100644 index 0000000000..fe57c50fe3 --- /dev/null +++ b/cpp/misra/test/rules/RULE-13-1-2/VirtualAndNonVirtualClassInTheHierarchy.testref @@ -0,0 +1 @@ +cpp/common/test/rules/virtualandnonvirtualclassinthehierarchy/VirtualAndNonVirtualClassInTheHierarchy.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-13-3-2/OverridingShallSpecifyDifferentDefaultArguments.testref b/cpp/misra/test/rules/RULE-13-3-2/OverridingShallSpecifyDifferentDefaultArguments.testref new file mode 100644 index 0000000000..7e06403515 --- /dev/null +++ b/cpp/misra/test/rules/RULE-13-3-2/OverridingShallSpecifyDifferentDefaultArguments.testref @@ -0,0 +1 @@ +cpp/common/test/rules/overridingshallspecifydifferentdefaultarguments/OverridingShallSpecifyDifferentDefaultArguments.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-13-3-4/PotentiallyVirtualPointerOnlyComparesToNullptr.testref b/cpp/misra/test/rules/RULE-13-3-4/PotentiallyVirtualPointerOnlyComparesToNullptr.testref new file mode 100644 index 0000000000..ca8eab9681 --- /dev/null +++ b/cpp/misra/test/rules/RULE-13-3-4/PotentiallyVirtualPointerOnlyComparesToNullptr.testref @@ -0,0 +1 @@ +cpp/common/test/rules/potentiallyvirtualpointeronlycomparestonullptr/PotentiallyVirtualPointerOnlyComparesToNullptr.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-15-1-1/ObjectsDynamicTypeUsedFromConstructorOrDestructor.testref b/cpp/misra/test/rules/RULE-15-1-1/ObjectsDynamicTypeUsedFromConstructorOrDestructor.testref new file mode 100644 index 0000000000..596f74b010 --- /dev/null +++ b/cpp/misra/test/rules/RULE-15-1-1/ObjectsDynamicTypeUsedFromConstructorOrDestructor.testref @@ -0,0 +1 @@ +cpp/common/test/rules/objectsdynamictypeusedfromconstructorordestructor/ObjectsDynamicTypeUsedFromConstructorOrDestructor.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-15-1-2/InitializeAllVirtualBaseClasses.testref b/cpp/misra/test/rules/RULE-15-1-2/InitializeAllVirtualBaseClasses.testref new file mode 100644 index 0000000000..ac8c5e1a83 --- /dev/null +++ b/cpp/misra/test/rules/RULE-15-1-2/InitializeAllVirtualBaseClasses.testref @@ -0,0 +1 @@ +cpp/common/test/rules/initializeallvirtualbaseclasses/InitializeAllVirtualBaseClasses.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-15-1-5/InitializerListConstructorIsTheOnlyConstructor.testref b/cpp/misra/test/rules/RULE-15-1-5/InitializerListConstructorIsTheOnlyConstructor.testref new file mode 100644 index 0000000000..49b73d06a9 --- /dev/null +++ b/cpp/misra/test/rules/RULE-15-1-5/InitializerListConstructorIsTheOnlyConstructor.testref @@ -0,0 +1 @@ +cpp/common/test/rules/initializerlistconstructoristheonlyconstructor/InitializerListConstructorIsTheOnlyConstructor.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-16-5-2/AddressOfOperatorOverloaded.testref b/cpp/misra/test/rules/RULE-16-5-2/AddressOfOperatorOverloaded.testref new file mode 100644 index 0000000000..1f2a126671 --- /dev/null +++ b/cpp/misra/test/rules/RULE-16-5-2/AddressOfOperatorOverloaded.testref @@ -0,0 +1 @@ +cpp/common/test/rules/addressofoperatoroverloaded/AddressOfOperatorOverloaded.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-17-8-1/FunctionTemplatesExplicitlySpecialized.testref b/cpp/misra/test/rules/RULE-17-8-1/FunctionTemplatesExplicitlySpecialized.testref new file mode 100644 index 0000000000..6a284e2cbb --- /dev/null +++ b/cpp/misra/test/rules/RULE-17-8-1/FunctionTemplatesExplicitlySpecialized.testref @@ -0,0 +1 @@ +cpp/common/test/rules/functiontemplatesexplicitlyspecialized/FunctionTemplatesExplicitlySpecialized.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-18-1-1/ExceptionObjectHavePointerType.testref b/cpp/misra/test/rules/RULE-18-1-1/ExceptionObjectHavePointerType.testref new file mode 100644 index 0000000000..24d4229225 --- /dev/null +++ b/cpp/misra/test/rules/RULE-18-1-1/ExceptionObjectHavePointerType.testref @@ -0,0 +1 @@ +cpp/common/test/rules/exceptionobjecthavepointertype/ExceptionObjectHavePointerType.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-18-1-2/EmptyThrowOnlyWithinACatchHandler.testref b/cpp/misra/test/rules/RULE-18-1-2/EmptyThrowOnlyWithinACatchHandler.testref new file mode 100644 index 0000000000..f3c961d8f1 --- /dev/null +++ b/cpp/misra/test/rules/RULE-18-1-2/EmptyThrowOnlyWithinACatchHandler.testref @@ -0,0 +1 @@ +cpp/common/test/rules/emptythrowonlywithinacatchhandler/EmptyThrowOnlyWithinACatchHandler.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-18-5-1/NoexceptFunctionShouldNotPropagateToTheCaller.testref b/cpp/misra/test/rules/RULE-18-5-1/NoexceptFunctionShouldNotPropagateToTheCaller.testref new file mode 100644 index 0000000000..76dc55827f --- /dev/null +++ b/cpp/misra/test/rules/RULE-18-5-1/NoexceptFunctionShouldNotPropagateToTheCaller.testref @@ -0,0 +1 @@ +cpp/common/test/rules/noexceptfunctionshouldnotpropagatetothecaller/NoexceptFunctionShouldNotPropagateToTheCaller.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-19-0-2/FunctionLikeMacrosDefined.testref b/cpp/misra/test/rules/RULE-19-0-2/FunctionLikeMacrosDefined.testref new file mode 100644 index 0000000000..1f07b047a6 --- /dev/null +++ b/cpp/misra/test/rules/RULE-19-0-2/FunctionLikeMacrosDefined.testref @@ -0,0 +1 @@ +cpp/common/test/rules/functionlikemacrosdefined/FunctionLikeMacrosDefined.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-19-3-2/MacroParameterFollowingHash.testref b/cpp/misra/test/rules/RULE-19-3-2/MacroParameterFollowingHash.testref new file mode 100644 index 0000000000..a5eb010410 --- /dev/null +++ b/cpp/misra/test/rules/RULE-19-3-2/MacroParameterFollowingHash.testref @@ -0,0 +1 @@ +cpp/common/test/rules/macroparameterfollowinghash/MacroParameterFollowingHash.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-19-3-3/AMixedUseMacroArgumentSubjectToExpansion.testref b/cpp/misra/test/rules/RULE-19-3-3/AMixedUseMacroArgumentSubjectToExpansion.testref new file mode 100644 index 0000000000..8061bfd2ec --- /dev/null +++ b/cpp/misra/test/rules/RULE-19-3-3/AMixedUseMacroArgumentSubjectToExpansion.testref @@ -0,0 +1 @@ +cpp/common/test/rules/amixedusemacroargumentsubjecttoexpansion/AMixedUseMacroArgumentSubjectToExpansion.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-21-10-3/CsignalFacilitiesUsed.testref b/cpp/misra/test/rules/RULE-21-10-3/CsignalFacilitiesUsed.testref new file mode 100644 index 0000000000..2342517408 --- /dev/null +++ b/cpp/misra/test/rules/RULE-21-10-3/CsignalFacilitiesUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/csignalfacilitiesused/CsignalFacilitiesUsed.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-21-10-3/CsignalTypesShallNotBeUsed.testref b/cpp/misra/test/rules/RULE-21-10-3/CsignalTypesShallNotBeUsed.testref new file mode 100644 index 0000000000..3d398d799b --- /dev/null +++ b/cpp/misra/test/rules/RULE-21-10-3/CsignalTypesShallNotBeUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/csignaltypesused/CsignalTypesUsed.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-21-10-3/CsignalTypesUsed.testref b/cpp/misra/test/rules/RULE-21-10-3/CsignalTypesUsed.testref new file mode 100644 index 0000000000..3d398d799b --- /dev/null +++ b/cpp/misra/test/rules/RULE-21-10-3/CsignalTypesUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/csignaltypesused/CsignalTypesUsed.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-21-2-1/AtofAtoiAtolAndAtollUsed.testref b/cpp/misra/test/rules/RULE-21-2-1/AtofAtoiAtolAndAtollUsed.testref new file mode 100644 index 0000000000..1b12920284 --- /dev/null +++ b/cpp/misra/test/rules/RULE-21-2-1/AtofAtoiAtolAndAtollUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/atofatoiatolandatollused/AtofAtoiAtolAndAtollUsed.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-21-2-4/MacroOffsetofShallNotBeUsed.testref b/cpp/misra/test/rules/RULE-21-2-4/MacroOffsetofShallNotBeUsed.testref new file mode 100644 index 0000000000..022fef6071 --- /dev/null +++ b/cpp/misra/test/rules/RULE-21-2-4/MacroOffsetofShallNotBeUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/macrooffsetofused/MacroOffsetofUsed.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-21-6-4/GlobalSizedOperatorDeleteShallBeDefined.testref b/cpp/misra/test/rules/RULE-21-6-4/GlobalSizedOperatorDeleteShallBeDefined.testref new file mode 100644 index 0000000000..4d1e21d4cb --- /dev/null +++ b/cpp/misra/test/rules/RULE-21-6-4/GlobalSizedOperatorDeleteShallBeDefined.testref @@ -0,0 +1 @@ +cpp/common/test/rules/globalsizedoperatordeletenotdefined/GlobalSizedOperatorDeleteNotDefined.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-21-6-4/GlobalUnsizedOperatorDeleteShallBeDefined.testref b/cpp/misra/test/rules/RULE-21-6-4/GlobalUnsizedOperatorDeleteShallBeDefined.testref new file mode 100644 index 0000000000..f2fcc2eded --- /dev/null +++ b/cpp/misra/test/rules/RULE-21-6-4/GlobalUnsizedOperatorDeleteShallBeDefined.testref @@ -0,0 +1 @@ +cpp/common/test/rules/globalunsizedoperatordeletenotdefined/GlobalUnsizedOperatorDeleteNotDefined.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-26-3-1/VectorShouldNotBeSpecializedWithBool.testref b/cpp/misra/test/rules/RULE-26-3-1/VectorShouldNotBeSpecializedWithBool.testref new file mode 100644 index 0000000000..a934690acb --- /dev/null +++ b/cpp/misra/test/rules/RULE-26-3-1/VectorShouldNotBeSpecializedWithBool.testref @@ -0,0 +1 @@ +cpp/common/test/rules/vectorshouldnotbespecializedwithbool/VectorShouldNotBeSpecializedWithBool.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-28-6-2/ForwardingReferencesAndForwardNotUsedTogether.testref b/cpp/misra/test/rules/RULE-28-6-2/ForwardingReferencesAndForwardNotUsedTogether.testref new file mode 100644 index 0000000000..d56acb8415 --- /dev/null +++ b/cpp/misra/test/rules/RULE-28-6-2/ForwardingReferencesAndForwardNotUsedTogether.testref @@ -0,0 +1 @@ +cpp/common/test/rules/forwardingreferencesandforwardnotusedtogether/ForwardingReferencesAndForwardNotUsedTogether.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-30-0-1/CstdioFunctionsShallNotBeUsed.testref b/cpp/misra/test/rules/RULE-30-0-1/CstdioFunctionsShallNotBeUsed.testref new file mode 100644 index 0000000000..5f8b3d8a9a --- /dev/null +++ b/cpp/misra/test/rules/RULE-30-0-1/CstdioFunctionsShallNotBeUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/cstdiofunctionsused/CstdioFunctionsUsed.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-30-0-1/CstdioMacrosShallNotBeUsed.testref b/cpp/misra/test/rules/RULE-30-0-1/CstdioMacrosShallNotBeUsed.testref new file mode 100644 index 0000000000..a1ba376c3b --- /dev/null +++ b/cpp/misra/test/rules/RULE-30-0-1/CstdioMacrosShallNotBeUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/cstdiomacrosused/CstdioMacrosUsed.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-30-0-1/CstdioTypesShallNotBeUsed.testref b/cpp/misra/test/rules/RULE-30-0-1/CstdioTypesShallNotBeUsed.testref new file mode 100644 index 0000000000..4c08a75cfe --- /dev/null +++ b/cpp/misra/test/rules/RULE-30-0-1/CstdioTypesShallNotBeUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/cstdiotypesused/CstdioTypesUsed.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-5-13-1/BackslashCharacterMisuse.testref b/cpp/misra/test/rules/RULE-5-13-1/BackslashCharacterMisuse.testref new file mode 100644 index 0000000000..924122e38e --- /dev/null +++ b/cpp/misra/test/rules/RULE-5-13-1/BackslashCharacterMisuse.testref @@ -0,0 +1 @@ +cpp/common/test/rules/backslashcharactermisuse/BackslashCharacterMisuse.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-5-13-2/NonTerminatedEscapeSequences.testref b/cpp/misra/test/rules/RULE-5-13-2/NonTerminatedEscapeSequences.testref new file mode 100644 index 0000000000..bfed44b1fd --- /dev/null +++ b/cpp/misra/test/rules/RULE-5-13-2/NonTerminatedEscapeSequences.testref @@ -0,0 +1 @@ +cpp/common/test/rules/nonterminatedescapesequences/NonTerminatedEscapeSequences.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-5-13-3/OctalConstantsUsed.testref b/cpp/misra/test/rules/RULE-5-13-3/OctalConstantsUsed.testref new file mode 100644 index 0000000000..97c466a866 --- /dev/null +++ b/cpp/misra/test/rules/RULE-5-13-3/OctalConstantsUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/useofnonzerooctalliteral/UseOfNonZeroOctalLiteral.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-5-13-4/UnsignedIntegerLiteralsNotAppropriatelySuffixed.testref b/cpp/misra/test/rules/RULE-5-13-4/UnsignedIntegerLiteralsNotAppropriatelySuffixed.testref new file mode 100644 index 0000000000..9133a84ce4 --- /dev/null +++ b/cpp/misra/test/rules/RULE-5-13-4/UnsignedIntegerLiteralsNotAppropriatelySuffixed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/unsignedintegerliteralsnotappropriatelysuffixed/UnsignedIntegerLiteralsNotAppropriatelySuffixed.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-5-13-5/LowercaseLStartsInLiteralSuffix.testref b/cpp/misra/test/rules/RULE-5-13-5/LowercaseLStartsInLiteralSuffix.testref new file mode 100644 index 0000000000..760d407a2d --- /dev/null +++ b/cpp/misra/test/rules/RULE-5-13-5/LowercaseLStartsInLiteralSuffix.testref @@ -0,0 +1 @@ +cpp/common/test/rules/lowercaselstartsinliteralsuffix/LowercaseLStartsInLiteralSuffix.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-5-7-1/CharacterSequenceUsedWithinACStyleComment.testref b/cpp/misra/test/rules/RULE-5-7-1/CharacterSequenceUsedWithinACStyleComment.testref new file mode 100644 index 0000000000..971b1953f7 --- /dev/null +++ b/cpp/misra/test/rules/RULE-5-7-1/CharacterSequenceUsedWithinACStyleComment.testref @@ -0,0 +1 @@ +cpp/common/test/rules/charactersequenceusedwithinacstylecomment/CharacterSequenceUsedWithinACStyleComment.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-5-7-3/LineSplicingUsedInComments.testref b/cpp/misra/test/rules/RULE-5-7-3/LineSplicingUsedInComments.testref new file mode 100644 index 0000000000..7874a476a0 --- /dev/null +++ b/cpp/misra/test/rules/RULE-5-7-3/LineSplicingUsedInComments.testref @@ -0,0 +1 @@ +cpp/common/test/rules/linesplicingusedincomments/LineSplicingUsedInComments.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-6-0-3/GlobalNamespaceDeclarations.testref b/cpp/misra/test/rules/RULE-6-0-3/GlobalNamespaceDeclarations.testref new file mode 100644 index 0000000000..8f71738005 --- /dev/null +++ b/cpp/misra/test/rules/RULE-6-0-3/GlobalNamespaceDeclarations.testref @@ -0,0 +1 @@ +cpp/common/test/rules/globalnamespacedeclarations/GlobalNamespaceDeclarations.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-6-0-4/NonGlobalFunctionMain.testref b/cpp/misra/test/rules/RULE-6-0-4/NonGlobalFunctionMain.testref new file mode 100644 index 0000000000..e149f3a33b --- /dev/null +++ b/cpp/misra/test/rules/RULE-6-0-4/NonGlobalFunctionMain.testref @@ -0,0 +1 @@ +cpp/common/test/rules/nonglobalfunctionmain/NonGlobalFunctionMain.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-6-4-2/DefinitionShallBeConsideredForUnqualifiedLookup.testref b/cpp/misra/test/rules/RULE-6-4-2/DefinitionShallBeConsideredForUnqualifiedLookup.testref new file mode 100644 index 0000000000..7a5ae74d2e --- /dev/null +++ b/cpp/misra/test/rules/RULE-6-4-2/DefinitionShallBeConsideredForUnqualifiedLookup.testref @@ -0,0 +1 @@ +cpp/common/test/rules/definitionnotconsideredforunqualifiedlookup/DefinitionNotConsideredForUnqualifiedLookup.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-6-4-2/InheritedNonOverridableMemberFunction.testref b/cpp/misra/test/rules/RULE-6-4-2/InheritedNonOverridableMemberFunction.testref new file mode 100644 index 0000000000..2fb9608ee8 --- /dev/null +++ b/cpp/misra/test/rules/RULE-6-4-2/InheritedNonOverridableMemberFunction.testref @@ -0,0 +1 @@ +cpp/common/test/rules/hiddeninheritednonoverridablememberfunction/HiddenInheritedNonOverridableMemberFunction.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-6-4-2/InheritedOverridableMemberFunction.testref b/cpp/misra/test/rules/RULE-6-4-2/InheritedOverridableMemberFunction.testref new file mode 100644 index 0000000000..e768ced8d3 --- /dev/null +++ b/cpp/misra/test/rules/RULE-6-4-2/InheritedOverridableMemberFunction.testref @@ -0,0 +1 @@ +cpp/common/test/rules/hiddeninheritedoverridablememberfunction/HiddenInheritedOverridableMemberFunction.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-6-4-3/NameShallBeReferredUsingAQualifiedIdOrThis.testref b/cpp/misra/test/rules/RULE-6-4-3/NameShallBeReferredUsingAQualifiedIdOrThis.testref new file mode 100644 index 0000000000..ad5590bc1f --- /dev/null +++ b/cpp/misra/test/rules/RULE-6-4-3/NameShallBeReferredUsingAQualifiedIdOrThis.testref @@ -0,0 +1 @@ +cpp/common/test/rules/namenotreferredusingaqualifiedidorthis/NameNotReferredUsingAQualifiedIdOrThis.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-6-4-3/NameShallBeReferredUsingAQualifiedIdOrThisAudit.testref b/cpp/misra/test/rules/RULE-6-4-3/NameShallBeReferredUsingAQualifiedIdOrThisAudit.testref new file mode 100644 index 0000000000..f7ff9100a6 --- /dev/null +++ b/cpp/misra/test/rules/RULE-6-4-3/NameShallBeReferredUsingAQualifiedIdOrThisAudit.testref @@ -0,0 +1 @@ +cpp/common/test/rules/namenotreferredusingaqualifiedidorthisaudit/NameNotReferredUsingAQualifiedIdOrThisAudit.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-6-8-2/ReturnReferenceOrPointerToAutomaticLocalVariable.testref b/cpp/misra/test/rules/RULE-6-8-2/ReturnReferenceOrPointerToAutomaticLocalVariable.testref new file mode 100644 index 0000000000..45dbffde00 --- /dev/null +++ b/cpp/misra/test/rules/RULE-6-8-2/ReturnReferenceOrPointerToAutomaticLocalVariable.testref @@ -0,0 +1 @@ +cpp/common/test/rules/returnreferenceorpointertoautomaticlocalvariable/ReturnReferenceOrPointerToAutomaticLocalVariable.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-7-11-1/NullptrNotTheOnlyFormOfTheNullPointerConstant.testref b/cpp/misra/test/rules/RULE-7-11-1/NullptrNotTheOnlyFormOfTheNullPointerConstant.testref new file mode 100644 index 0000000000..aeb655a341 --- /dev/null +++ b/cpp/misra/test/rules/RULE-7-11-1/NullptrNotTheOnlyFormOfTheNullPointerConstant.testref @@ -0,0 +1 @@ +cpp/common/test/rules/nullptrnottheonlyformofthenullpointerconstant/NullptrNotTheOnlyFormOfTheNullPointerConstant.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-7-11-2/ArrayPassedAsFunctionArgumentDecayToAPointer.testref b/cpp/misra/test/rules/RULE-7-11-2/ArrayPassedAsFunctionArgumentDecayToAPointer.testref new file mode 100644 index 0000000000..06f2ec8fbb --- /dev/null +++ b/cpp/misra/test/rules/RULE-7-11-2/ArrayPassedAsFunctionArgumentDecayToAPointer.testref @@ -0,0 +1 @@ +cpp/common/test/rules/arraypassedasfunctionargumentdecaytoapointer/ArrayPassedAsFunctionArgumentDecayToAPointer.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-8-18-2/ResultOfAnAssignmentOperatorShouldNotBeUsed.testref b/cpp/misra/test/rules/RULE-8-18-2/ResultOfAnAssignmentOperatorShouldNotBeUsed.testref new file mode 100644 index 0000000000..1e29dba140 --- /dev/null +++ b/cpp/misra/test/rules/RULE-8-18-2/ResultOfAnAssignmentOperatorShouldNotBeUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-8-19-1/CommaOperatorShouldNotBeUsed.testref b/cpp/misra/test/rules/RULE-8-19-1/CommaOperatorShouldNotBeUsed.testref new file mode 100644 index 0000000000..845133096b --- /dev/null +++ b/cpp/misra/test/rules/RULE-8-19-1/CommaOperatorShouldNotBeUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/commaoperatorused/CommaOperatorUsed.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-8-2-10/FunctionsCallThemselvesEitherDirectlyOrIndirectly.testref b/cpp/misra/test/rules/RULE-8-2-10/FunctionsCallThemselvesEitherDirectlyOrIndirectly.testref new file mode 100644 index 0000000000..f459a29bf1 --- /dev/null +++ b/cpp/misra/test/rules/RULE-8-2-10/FunctionsCallThemselvesEitherDirectlyOrIndirectly.testref @@ -0,0 +1 @@ +cpp/common/test/rules/functionscallthemselveseitherdirectlyorindirectly/FunctionsCallThemselvesEitherDirectlyOrIndirectly.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-8-2-4/CastsBetweenAPointerToFunctionAndAnyOtherType.testref b/cpp/misra/test/rules/RULE-8-2-4/CastsBetweenAPointerToFunctionAndAnyOtherType.testref new file mode 100644 index 0000000000..e7bde2ea08 --- /dev/null +++ b/cpp/misra/test/rules/RULE-8-2-4/CastsBetweenAPointerToFunctionAndAnyOtherType.testref @@ -0,0 +1 @@ +cpp/common/test/rules/castsbetweenapointertofunctionandanyothertype/CastsBetweenAPointerToFunctionAndAnyOtherType.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-8-2-5/ReinterpretCastShallNotBeUsed.testref b/cpp/misra/test/rules/RULE-8-2-5/ReinterpretCastShallNotBeUsed.testref new file mode 100644 index 0000000000..81f18c2d9c --- /dev/null +++ b/cpp/misra/test/rules/RULE-8-2-5/ReinterpretCastShallNotBeUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/reinterpretcastused/ReinterpretCastUsed.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-8-20-1/UnsignedOperationWithConstantOperandsWraps.testref b/cpp/misra/test/rules/RULE-8-20-1/UnsignedOperationWithConstantOperandsWraps.testref new file mode 100644 index 0000000000..148997676e --- /dev/null +++ b/cpp/misra/test/rules/RULE-8-20-1/UnsignedOperationWithConstantOperandsWraps.testref @@ -0,0 +1 @@ +cpp/common/test/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-8-3-1/BuiltInUnaryOperatorAppliedToUnsignedExpression.testref b/cpp/misra/test/rules/RULE-8-3-1/BuiltInUnaryOperatorAppliedToUnsignedExpression.testref new file mode 100644 index 0000000000..bd12c39fbd --- /dev/null +++ b/cpp/misra/test/rules/RULE-8-3-1/BuiltInUnaryOperatorAppliedToUnsignedExpression.testref @@ -0,0 +1 @@ +cpp/common/test/rules/builtinunaryoperatorappliedtounsignedexpression/BuiltInUnaryOperatorAppliedToUnsignedExpression.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-9-3-1/LoopBodyCompoundCondition.testref b/cpp/misra/test/rules/RULE-9-3-1/LoopBodyCompoundCondition.testref new file mode 100644 index 0000000000..84dc7caf76 --- /dev/null +++ b/cpp/misra/test/rules/RULE-9-3-1/LoopBodyCompoundCondition.testref @@ -0,0 +1 @@ +cpp/common/test/rules/loopcompoundcondition/LoopCompoundCondition.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-9-3-1/SwitchBodyCompoundCondition.testref b/cpp/misra/test/rules/RULE-9-3-1/SwitchBodyCompoundCondition.testref new file mode 100644 index 0000000000..f02b02ba85 --- /dev/null +++ b/cpp/misra/test/rules/RULE-9-3-1/SwitchBodyCompoundCondition.testref @@ -0,0 +1 @@ +cpp/common/test/rules/switchcompoundcondition/SwitchCompoundCondition.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-9-6-1/GotoStatementShouldNotBeUsed.testref b/cpp/misra/test/rules/RULE-9-6-1/GotoStatementShouldNotBeUsed.testref new file mode 100644 index 0000000000..44d306f80c --- /dev/null +++ b/cpp/misra/test/rules/RULE-9-6-1/GotoStatementShouldNotBeUsed.testref @@ -0,0 +1 @@ +cpp/common/test/rules/gotostatementshouldnotbeused/GotoStatementShouldNotBeUsed.ql \ No newline at end of file diff --git a/cpp/misra/test/rules/RULE-9-6-2/GotoReferenceALabelInSurroundingBlock.testref b/cpp/misra/test/rules/RULE-9-6-2/GotoReferenceALabelInSurroundingBlock.testref new file mode 100644 index 0000000000..7502d9431c --- /dev/null +++ b/cpp/misra/test/rules/RULE-9-6-2/GotoReferenceALabelInSurroundingBlock.testref @@ -0,0 +1 @@ +cpp/common/test/rules/gotoreferencealabelinsurroundingblock/GotoReferenceALabelInSurroundingBlock.ql \ No newline at end of file diff --git a/rule_packages/c/Banned.json b/rule_packages/c/Banned.json index 42decbb3e3..cab9ffc8c7 100644 --- a/rule_packages/c/Banned.json +++ b/rule_packages/c/Banned.json @@ -245,6 +245,7 @@ "precision": "very-high", "severity": "error", "short_name": "AtofAtoiAtolAndAtollOfStdlibhUsed", + "shared_implementation_short_name": "AtofAtoiAtolAndAtollUsed", "tags": [ "correctness" ] @@ -337,6 +338,7 @@ "precision": "very-high", "severity": "error", "short_name": "OctalConstantsUsed", + "shared_implementation_short_name": "UseOfNonZeroOctalLiteral", "tags": [ "readability", "correctness", diff --git a/rule_packages/c/BitfieldTypes.json b/rule_packages/c/BitfieldTypes.json index 4e93f3371a..76490d73d1 100644 --- a/rule_packages/c/BitfieldTypes.json +++ b/rule_packages/c/BitfieldTypes.json @@ -12,6 +12,7 @@ "precision": "very-high", "severity": "error", "short_name": "BitFieldsShallOnlyBeDeclaredWithAnAppropriateType", + "shared_implementation_short_name": "BitFieldShallHaveAnAppropriateType", "tags": [] } ], @@ -29,6 +30,7 @@ "precision": "very-high", "severity": "error", "short_name": "SingleBitNamedBitFieldsOfASignedType", + "shared_implementation_short_name": "NamedBitFieldsWithSignedIntegerType", "tags": [] } ], diff --git a/rule_packages/c/Declarations7.json b/rule_packages/c/Declarations7.json index cd3b3e6b18..b1be4f9d55 100644 --- a/rule_packages/c/Declarations7.json +++ b/rule_packages/c/Declarations7.json @@ -57,6 +57,7 @@ "precision": "very-high", "severity": "error", "short_name": "ValueImplicitEnumerationConstantNotUnique", + "shared_implementation_short_name": "NonUniqueEnumerationConstant", "tags": [ "correctness", "readability" diff --git a/rule_packages/c/IntegerOverflow.json b/rule_packages/c/IntegerOverflow.json index 5edc90eb21..0fb1c5a4e7 100644 --- a/rule_packages/c/IntegerOverflow.json +++ b/rule_packages/c/IntegerOverflow.json @@ -12,6 +12,7 @@ "precision": "medium", "severity": "error", "short_name": "UnsignedIntegerOperationsWrapAround", + "shared_implementation_short_name": "UnsignedOperationWithConstantOperandsWraps", "tags": [ "correctness", "security" diff --git a/rule_packages/c/Preprocessor2.json b/rule_packages/c/Preprocessor2.json index 9eeb7beba8..546f426135 100644 --- a/rule_packages/c/Preprocessor2.json +++ b/rule_packages/c/Preprocessor2.json @@ -12,6 +12,7 @@ "precision": "very-high", "severity": "warning", "short_name": "MoreThanOneHashOperatorInMacroDefinition", + "shared_implementation_short_name": "MacroParameterFollowingHash", "tags": [ "correctness" ], @@ -35,9 +36,10 @@ "precision": "high", "severity": "warning", "short_name": "MacroParameterUsedAsHashOperand", + "shared_implementation_short_name": "AMixedUseMacroArgumentSubjectToExpansion", "tags": [ - "maintainability", - "readability" + "maintainability", + "readability" ] } ], @@ -56,8 +58,8 @@ "severity": "warning", "short_name": "UndefShouldNotBeUsed", "tags": [ - "maintainability", - "readability" + "maintainability", + "readability" ] } ], diff --git a/rule_packages/c/Preprocessor6.json b/rule_packages/c/Preprocessor6.json index be0ae84851..0bb7f34f90 100644 --- a/rule_packages/c/Preprocessor6.json +++ b/rule_packages/c/Preprocessor6.json @@ -12,6 +12,7 @@ "precision": "medium", "severity": "recommendation", "short_name": "FunctionOverFunctionLikeMacro", + "shared_implementation_short_name": "FunctionLikeMacrosDefined", "tags": [ "external/misra/audit", "maintainability", diff --git a/rule_packages/c/SideEffects1.json b/rule_packages/c/SideEffects1.json index e66f4c3136..821fb24d3c 100644 --- a/rule_packages/c/SideEffects1.json +++ b/rule_packages/c/SideEffects1.json @@ -131,6 +131,7 @@ "precision": "very-high", "severity": "error", "short_name": "ResultOfAnAssignmentOperatorShouldNotBeUsed", + "shared_implementation_short_name": "ResultOfAnAssignmentOperatorShouldNotBeUsed", "tags": [ "correctness", "readability" diff --git a/rule_packages/c/Statements2.json b/rule_packages/c/Statements2.json index 8aa44c5091..cb616429be 100644 --- a/rule_packages/c/Statements2.json +++ b/rule_packages/c/Statements2.json @@ -33,6 +33,7 @@ "precision": "high", "severity": "recommendation", "short_name": "GotoLabelBlockCondition", + "shared_implementation_short_name": "GotoReferenceALabelInSurroundingBlock", "tags": [ "maintainability", "readability" @@ -102,4 +103,4 @@ "title": "A switch-expression shall not have essentially Boolean type" } } -} +} \ No newline at end of file diff --git a/rule_packages/c/Statements3.json b/rule_packages/c/Statements3.json index 41463415a6..5471749a49 100644 --- a/rule_packages/c/Statements3.json +++ b/rule_packages/c/Statements3.json @@ -20,7 +20,7 @@ { "description": "if the body of a loop is not enclosed in braces, then this can lead to incorrect execution, and is hard for developers to maintain.", "kind": "problem", - "name": "the statement forming the body of a loop shall be a compound statement", + "name": "The statement forming the body of a loop shall be a compound statement", "precision": "very-high", "severity": "recommendation", "short_name": "LoopCompoundCondition", @@ -32,7 +32,7 @@ { "description": "if the body of a selection statement is not enclosed in braces, then this can lead to incorrect execution, and is hard for developers to maintain.", "kind": "problem", - "name": "the statement forming the body of a loop shall be a compound statement", + "name": "The statement forming the body of a slection statement shall be a compound statement", "precision": "very-high", "severity": "recommendation", "short_name": "SelectionCompoundCondition", diff --git a/rule_packages/c/Statements6.json b/rule_packages/c/Statements6.json index 101987f9c3..8d71f11cfd 100644 --- a/rule_packages/c/Statements6.json +++ b/rule_packages/c/Statements6.json @@ -12,6 +12,7 @@ "precision": "very-high", "severity": "error", "short_name": "GotoStatementUsed", + "shared_implementation_short_name": "GotoStatementShouldNotBeUsed", "tags": [ "correctness", "security" diff --git a/rule_packages/c/Syntax.json b/rule_packages/c/Syntax.json index d294c44183..b8899ccc97 100644 --- a/rule_packages/c/Syntax.json +++ b/rule_packages/c/Syntax.json @@ -53,6 +53,7 @@ "precision": "very-high", "severity": "warning", "short_name": "OctalAndHexadecimalEscapeSequencesNotTerminated", + "shared_implementation_short_name": "NonTerminatedEscapeSequences", "tags": [ "maintainability", "readability", @@ -79,7 +80,7 @@ "maintainability", "readability", "correctness" - ] + ] } ], "title": "Sections of code should not be commented out" @@ -96,7 +97,7 @@ "precision": "very-high", "severity": "recommendation", "short_name": "IdentifiersInTheSameNameSpaceUnambiguous", - "shared_implementation_short_name" : "DifferentIdentifiersNotTypographicallyUnambiguous", + "shared_implementation_short_name": "DifferentIdentifiersNotTypographicallyUnambiguous", "tags": [ "readability", "maintainability" @@ -137,6 +138,7 @@ "precision": "very-high", "severity": "recommendation", "short_name": "LowercaseCharacterLUsedInLiteralSuffix", + "shared_implementation_short_name": "LowercaseLStartsInLiteralSuffix", "tags": [ "maintainability", "readability" diff --git a/rule_packages/cpp/BannedFunctions.json b/rule_packages/cpp/BannedFunctions.json index bb89ab2320..8ef93db1a0 100644 --- a/rule_packages/cpp/BannedFunctions.json +++ b/rule_packages/cpp/BannedFunctions.json @@ -189,6 +189,7 @@ "precision": "very-high", "severity": "error", "short_name": "MacroOffsetofUsed", + "shared_implementation_short_name": "MacroOffsetofUsed", "tags": [ "security", "scope/single-translation-unit" diff --git a/rule_packages/cpp/BannedLibraries.json b/rule_packages/cpp/BannedLibraries.json index 09b5d2f224..fce11b9eca 100644 --- a/rule_packages/cpp/BannedLibraries.json +++ b/rule_packages/cpp/BannedLibraries.json @@ -114,6 +114,7 @@ "precision": "very-high", "severity": "warning", "short_name": "CsignalFunctionsUsed", + "shared_implementation_short_name": "CsignalFunctionsUsed", "tags": [ "maintainability", "correctness", @@ -127,6 +128,7 @@ "precision": "very-high", "severity": "warning", "short_name": "CsignalTypesUsed", + "shared_implementation_short_name": "CsignalTypesUsed", "tags": [ "maintainability", "correctness", @@ -177,6 +179,7 @@ "precision": "very-high", "severity": "warning", "short_name": "CstdioFunctionsUsed", + "shared_implementation_short_name": "CstdioFunctionsUsed", "tags": [ "maintainability", "correctness", @@ -190,6 +193,7 @@ "precision": "very-high", "severity": "warning", "short_name": "CstdioMacrosUsed", + "shared_implementation_short_name": "CstdioMacrosUsed", "tags": [ "maintainability", "correctness", @@ -203,6 +207,7 @@ "precision": "very-high", "severity": "warning", "short_name": "CstdioTypesUsed", + "shared_implementation_short_name": "CstdioTypesUsed", "tags": [ "maintainability", "correctness", diff --git a/rule_packages/cpp/BannedSyntax.json b/rule_packages/cpp/BannedSyntax.json index 0f559e60b7..8e307c02db 100644 --- a/rule_packages/cpp/BannedSyntax.json +++ b/rule_packages/cpp/BannedSyntax.json @@ -169,6 +169,7 @@ "precision": "very-high", "severity": "error", "short_name": "ReinterpretCastUsed", + "shared_implementation_short_name": "ReinterpretCastUsed", "tags": [ "correctness", "security", @@ -194,6 +195,7 @@ "precision": "very-high", "severity": "error", "short_name": "GotoStatementUsed", + "shared_implementation_short_name": "GotoStatementShouldNotBeUsed", "tags": [ "correctness", "security", @@ -266,6 +268,7 @@ "name": "The asm declaration shall not be used", "precision": "very-high", "severity": "error", + "shared_implementation_short_name": "AsmDeclarationUsed", "short_name": "AsmDeclarationUsed", "tags": [ "correctness", diff --git a/rule_packages/cpp/BannedTypes.json b/rule_packages/cpp/BannedTypes.json index 4a45433746..e84399b928 100644 --- a/rule_packages/cpp/BannedTypes.json +++ b/rule_packages/cpp/BannedTypes.json @@ -41,6 +41,7 @@ "precision": "very-high", "severity": "warning", "short_name": "VectorboolSpecializationUsed", + "shared_implementation_short_name": "VectorShouldNotBeSpecializedWithBool", "tags": [ "correctness", "scope/single-translation-unit" diff --git a/rule_packages/cpp/Comments.json b/rule_packages/cpp/Comments.json index 7af32f62c1..2421bec52f 100644 --- a/rule_packages/cpp/Comments.json +++ b/rule_packages/cpp/Comments.json @@ -16,6 +16,7 @@ "precision": "very-high", "severity": "warning", "short_name": "SingleLineCommentEndsWithSlash", + "shared_implementation_short_name": "LineSplicingUsedInComments", "tags": [ "correctness", "readability", @@ -94,6 +95,7 @@ "precision": "very-high", "severity": "warning", "short_name": "SlashStarUsedWithinACStyleComment", + "shared_implementation_short_name": "CharacterSequenceUsedWithinACStyleComment", "tags": [ "maintainability", "readability", diff --git a/rule_packages/cpp/Conditionals.json b/rule_packages/cpp/Conditionals.json index c2afb626e4..584df19420 100644 --- a/rule_packages/cpp/Conditionals.json +++ b/rule_packages/cpp/Conditionals.json @@ -78,6 +78,7 @@ "precision": "very-high", "severity": "recommendation", "short_name": "SwitchCompoundCondition", + "shared_implementation_short_name": "SwitchCompoundCondition", "tags": [ "maintainability", "readability" @@ -90,6 +91,7 @@ "precision": "very-high", "severity": "recommendation", "short_name": "LoopCompoundCondition", + "shared_implementation_short_name": "LoopCompoundCondition", "tags": [ "maintainability", "readability" diff --git a/rule_packages/cpp/Declarations.json b/rule_packages/cpp/Declarations.json index 65dfbf781e..a5b8ebeec3 100644 --- a/rule_packages/cpp/Declarations.json +++ b/rule_packages/cpp/Declarations.json @@ -50,6 +50,7 @@ "precision": "very-high", "severity": "error", "short_name": "GlobalSizedOperatorDeleteNotDefined", + "shared_implementation_short_name": "GlobalSizedOperatorDeleteNotDefined", "tags": [ "maintainability" ] @@ -61,6 +62,7 @@ "precision": "very-high", "severity": "error", "short_name": "GlobalUnsizedOperatorDeleteNotDefined", + "shared_implementation_short_name": "GlobalUnsizedOperatorDeleteNotDefined", "tags": [ "maintainability" ] @@ -216,6 +218,7 @@ "precision": "very-high", "severity": "recommendation", "short_name": "EnumerationUnderlyingBaseTypeNotExplicitlyDefined", + "shared_implementation_short_name": "EnumerationNotDefinedWithAnExplicitUnderlyingType", "tags": [ "readability", "maintainability" diff --git a/rule_packages/cpp/Exceptions1.json b/rule_packages/cpp/Exceptions1.json index d42c949b48..23b37778db 100644 --- a/rule_packages/cpp/Exceptions1.json +++ b/rule_packages/cpp/Exceptions1.json @@ -90,6 +90,7 @@ "precision": "very-high", "severity": "error", "short_name": "PointerExceptionObject", + "shared_implementation_short_name": "ExceptionObjectHavePointerType", "tags": [ "correctness" ] @@ -224,6 +225,7 @@ "severity": "error", "kind": "path-problem", "short_name": "NoExceptFunctionThrows", + "shared_implementation_short_name": "NoexceptFunctionShouldNotPropagateToTheCaller", "tags": [ "correctness" ] @@ -428,6 +430,7 @@ "precision": "very-high", "severity": "error", "short_name": "EmptyThrowOutsideCatch", + "shared_implementation_short_name": "EmptyThrowOnlyWithinACatchHandler", "tags": [ "correctness" ] diff --git a/rule_packages/cpp/Functions.json b/rule_packages/cpp/Functions.json index 7f21cf0873..367ab67437 100644 --- a/rule_packages/cpp/Functions.json +++ b/rule_packages/cpp/Functions.json @@ -87,6 +87,7 @@ "precision": "very-high", "severity": "error", "short_name": "RecursiveFunctions", + "shared_implementation_short_name": "FunctionsCallThemselvesEitherDirectlyOrIndirectly", "tags": [ "correctness", "maintainability" @@ -232,6 +233,7 @@ "precision": "very-high", "severity": "error", "short_name": "FunctionReturnAutomaticVarCondition", + "shared_implementation_short_name": "ReturnReferenceOrPointerToAutomaticLocalVariable", "tags": [ "correctness", "security" @@ -326,4 +328,4 @@ "title": "Do not return from a function declared [[noreturn]]" } } -} +} \ No newline at end of file diff --git a/rule_packages/cpp/ImportMisra23.json b/rule_packages/cpp/ImportMisra23.json index ced7198cff..243fc7cc20 100644 --- a/rule_packages/cpp/ImportMisra23.json +++ b/rule_packages/cpp/ImportMisra23.json @@ -500,6 +500,1234 @@ } ], "title": "Reads and writes on the same file stream shall be separated by a positioning operation" + }, + "RULE-8-19-1": { + "properties": { + "enforcement": "decidable", + "obligation": "advisory" + }, + "queries": [ + { + "description": "The comma operator should not be used.", + "kind": "problem", + "name": "The comma operator should not be used", + "precision": "very-high", + "severity": "error", + "short_name": "CommaOperatorShouldNotBeUsed", + "shared_implementation_short_name": "CommaOperatorUsed", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "The comma operator should not be used" + }, + "DIR-15-8-1": { + "properties": { + "allocated-target": [ + "implementation" + ], + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "User-provided copy assignment operators and move assignment operators shall handle self-assignment.", + "kind": "problem", + "name": "User-provided copy assignment operators and move assignment operators shall handle self-assignment", + "precision": "very-high", + "severity": "error", + "short_name": "CopyAndMoveAssignmentsShallHandleSelfAssignment", + "shared_implementation_short_name": "CopyAndMoveAssignmentsShallHandleSelfAssignment", + "tags": [] + } + ], + "title": "User-provided copy assignment operators and move assignment operators shall handle self-assignment" + }, + "RULE-10-0-1": { + "properties": { + "enforcement": "decidable", + "obligation": "advisory" + }, + "queries": [ + { + "description": "A declaration should not declare more than one variable or member variable.", + "kind": "problem", + "name": "Multiple declarations in the same local statement", + "precision": "very-high", + "severity": "recommendation", + "short_name": "UseSingleLocalDeclarators", + "shared_implementation_short_name": "MultipleLocalDeclarators", + "tags": [ + "readability", + "maintainability", + "scope/single-translation-unit" + ] + }, + { + "description": "A declaration should not declare more than one variable or member variable.", + "kind": "problem", + "name": "Multiple declarations in the same global or member declaration sequence", + "precision": "medium", + "severity": "recommendation", + "short_name": "UseSingleGlobalOrMemberDeclarators", + "shared_implementation_short_name": "MultipleGlobalOrMemberDeclarators", + "tags": [ + "readability", + "maintainability", + "scope/single-translation-unit" + ] + } + ], + "title": "A declaration should not declare more than one variable or member variable" + }, + "RULE-10-2-1": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "An enumeration shall be defined with an explicit underlying type.", + "kind": "problem", + "name": "An enumeration shall be defined with an explicit underlying type", + "precision": "very-high", + "severity": "error", + "short_name": "EnumerationNotDefinedWithAnExplicitUnderlyingType", + "shared_implementation_short_name": "EnumerationNotDefinedWithAnExplicitUnderlyingType", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "An enumeration shall be defined with an explicit underlying type" + }, + "RULE-10-4-1": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "The asm declaration shall not be used.", + "kind": "problem", + "name": "The asm declaration shall not be used", + "precision": "very-high", + "severity": "error", + "short_name": "AsmDeclarationShallNotBeUsed", + "shared_implementation_short_name": "AsmDeclarationUsed", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "The asm declaration shall not be used" + }, + "RULE-11-6-3": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique.", + "kind": "problem", + "name": "Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique", + "precision": "very-high", + "severity": "error", + "short_name": "NonUniqueEnumerationConstant", + "shared_implementation_short_name": "NonUniqueEnumerationConstant", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique" + }, + "RULE-12-2-2": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "A bit-field shall have an appropriate type.", + "kind": "problem", + "name": "A bit-field shall have an appropriate type", + "precision": "very-high", + "severity": "error", + "short_name": "BitFieldShallHaveAnAppropriateType", + "shared_implementation_short_name": "BitFieldShallHaveAnAppropriateType", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "A bit-field shall have an appropriate type" + }, + "RULE-12-2-3": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "A named bit-field with signed integer type shall not have a length of one bit.", + "kind": "problem", + "name": "A named bit-field with signed integer type shall not have a length of one bit", + "precision": "very-high", + "severity": "error", + "short_name": "SignedIntegerNamedBitFieldHaveALengthOfOneBit", + "shared_implementation_short_name": "NamedBitFieldsWithSignedIntegerType", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "A named bit-field with signed integer type shall not have a length of one bit" + }, + "RULE-13-1-2": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "An accessible base class shall not be both virtual and non-virtual in the same hierarchy.", + "kind": "problem", + "name": "An accessible base class shall not be both virtual and non-virtual in the same hierarchy", + "precision": "very-high", + "severity": "error", + "short_name": "VirtualAndNonVirtualClassInTheHierarchy", + "shared_implementation_short_name": "VirtualAndNonVirtualClassInTheHierarchy", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "An accessible base class shall not be both virtual and non-virtual in the same hierarchy" + }, + "RULE-13-3-2": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "Parameters in an overriding virtual function shall not specify different default arguments.", + "kind": "problem", + "name": "Parameters in an overriding virtual function shall not specify different default arguments", + "precision": "very-high", + "severity": "error", + "short_name": "OverridingShallSpecifyDifferentDefaultArguments", + "shared_implementation_short_name": "OverridingShallSpecifyDifferentDefaultArguments", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "Parameters in an overriding virtual function shall not specify different default arguments" + }, + "RULE-13-3-4": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "A comparison of a potentially virtual pointer to member function shall only be with nullptr.", + "kind": "problem", + "name": "A comparison of a potentially virtual pointer to member function shall only be with nullptr", + "precision": "very-high", + "severity": "error", + "short_name": "PotentiallyVirtualPointerOnlyComparesToNullptr", + "shared_implementation_short_name": "PotentiallyVirtualPointerOnlyComparesToNullptr", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "A comparison of a potentially virtual pointer to member function shall only be with nullptr" + }, + "RULE-15-1-1": { + "properties": { + "enforcement": "undecidable", + "obligation": "required" + }, + "queries": [ + { + "description": "An object\u2019s dynamic type shall not be used from within its constructor or destructor.", + "kind": "problem", + "name": "An object\u2019s dynamic type shall not be used from within its constructor or destructor", + "precision": "very-high", + "severity": "error", + "short_name": "ObjectsDynamicTypeUsedFromConstructorOrDestructor", + "shared_implementation_short_name": "ObjectsDynamicTypeUsedFromConstructorOrDestructor", + "tags": [ + "scope/system" + ] + } + ], + "title": "An object\u2019s dynamic type shall not be used from within its constructor or destructor" + }, + "RULE-15-1-2": { + "properties": { + "enforcement": "decidable", + "obligation": "advisory" + }, + "queries": [ + { + "description": "All constructors of a class should explicitly initialize all of its virtual base classes and immediate base classes.", + "kind": "problem", + "name": "All constructors of a class should explicitly initialize all of its virtual base classes and", + "precision": "very-high", + "severity": "error", + "short_name": "InitializeAllVirtualBaseClasses", + "shared_implementation_short_name": "InitializeAllVirtualBaseClasses", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "All constructors of a class should explicitly initialize all of its virtual base classes and immediate base classes" + }, + "RULE-15-1-5": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "A class shall only define an initializer-list constructor when it is the only constructor.", + "kind": "problem", + "name": "A class shall only define an initializer-list constructor when it is the only constructor", + "precision": "very-high", + "severity": "error", + "short_name": "InitializerListConstructorIsTheOnlyConstructor", + "shared_implementation_short_name": "InitializerListConstructorIsTheOnlyConstructor", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "A class shall only define an initializer-list constructor when it is the only constructor" + }, + "RULE-16-5-2": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "The address-of operator shall not be overloaded.", + "kind": "problem", + "name": "The address-of operator shall not be overloaded", + "precision": "very-high", + "severity": "error", + "short_name": "AddressOfOperatorOverloaded", + "shared_implementation_short_name": "AddressOfOperatorOverloaded", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "The address-of operator shall not be overloaded" + }, + "RULE-17-8-1": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "Function templates shall not be explicitly specialized.", + "kind": "problem", + "name": "Function templates shall not be explicitly specialized", + "precision": "very-high", + "severity": "error", + "short_name": "FunctionTemplatesExplicitlySpecialized", + "shared_implementation_short_name": "FunctionTemplatesExplicitlySpecialized", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "Function templates shall not be explicitly specialized" + }, + "RULE-18-1-1": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "An exception object shall not have pointer type.", + "kind": "problem", + "name": "An exception object shall not have pointer type", + "precision": "very-high", + "severity": "error", + "short_name": "ExceptionObjectHavePointerType", + "shared_implementation_short_name": "ExceptionObjectHavePointerType", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "An exception object shall not have pointer type" + }, + "RULE-18-1-2": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "An empty throw shall only occur within the compound-statement of a catch handler.", + "kind": "problem", + "name": "An empty throw shall only occur within the compound-statement of a catch handler", + "precision": "very-high", + "severity": "error", + "short_name": "EmptyThrowOnlyWithinACatchHandler", + "shared_implementation_short_name": "EmptyThrowOnlyWithinACatchHandler", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "An empty throw shall only occur within the compound-statement of a catch handler" + }, + "RULE-18-5-1": { + "properties": { + "enforcement": "undecidable", + "obligation": "advisory" + }, + "queries": [ + { + "description": "A noexcept function should not attempt to propagate an exception to the calling function.", + "kind": "path-problem", + "name": "A noexcept function should not attempt to propagate an exception to the calling function", + "precision": "very-high", + "severity": "error", + "short_name": "NoexceptFunctionShouldNotPropagateToTheCaller", + "shared_implementation_short_name": "NoexceptFunctionShouldNotPropagateToTheCaller", + "tags": [ + "scope/system" + ] + } + ], + "title": "A noexcept function should not attempt to propagate an exception to the calling function" + }, + "RULE-19-0-2": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "Function-like macros shall not be defined.", + "kind": "problem", + "name": "Function-like macros shall not be defined", + "precision": "very-high", + "severity": "error", + "short_name": "FunctionLikeMacrosDefined", + "shared_implementation_short_name": "FunctionLikeMacrosDefined", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "Function-like macros shall not be defined" + }, + "RULE-19-3-2": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "A macro parameter immediately following a # operator shall not be immediately followed by a ## operator.", + "kind": "problem", + "name": "A macro parameter immediately following a # operator shall not be immediately followed by a ##", + "precision": "very-high", + "severity": "error", + "short_name": "MacroParameterFollowingHash", + "shared_implementation_short_name": "MacroParameterFollowingHash", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "A macro parameter immediately following a # operator shall not be immediately followed by a ## operator" + }, + "RULE-19-3-3": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "The argument to a mixed-use macro parameter shall not be subject to further expansion.", + "kind": "problem", + "name": "The argument to a mixed-use macro parameter shall not be subject to further expansion", + "precision": "very-high", + "severity": "error", + "short_name": "AMixedUseMacroArgumentSubjectToExpansion", + "shared_implementation_short_name": "AMixedUseMacroArgumentSubjectToExpansion", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "The argument to a mixed-use macro parameter shall not be subject to further expansion" + }, + "RULE-21-10-3": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "Signal handling contains implementation-defined and undefined behaviour.", + "kind": "problem", + "name": "The facilities provided by the standard header file shall not be used", + "precision": "very-high", + "severity": "warning", + "short_name": "CsignalFacilitiesUsed", + "shared_implementation_short_name": "CsignalFunctionsUsed", + "tags": [ + "maintainability", + "correctness", + "scope/single-translation-unit" + ] + }, + { + "description": "The types provided by the standard header file shall not be used.", + "kind": "problem", + "name": "The signal-handling types of shall not be used", + "precision": "very-high", + "severity": "warning", + "short_name": "CsignalTypesShallNotBeUsed", + "shared_implementation_short_name": "CsignalTypesUsed", + "tags": [ + "maintainability", + "correctness", + "scope/single-translation-unit" + ] + } + ], + "title": "The facilities provided by the standard header file shall not be used" + }, + "RULE-21-2-1": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "The library functions atof, atoi, atol and atoll from shall not be used.", + "kind": "problem", + "name": "The library functions atof, atoi, atol and atoll from shall not be used", + "precision": "very-high", + "severity": "error", + "short_name": "AtofAtoiAtolAndAtollUsed", + "shared_implementation_short_name": "AtofAtoiAtolAndAtollUsed", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "The library functions atof, atoi, atol and atoll from shall not be used" + }, + "RULE-21-2-4": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "The macro offsetof shall not be used.", + "kind": "problem", + "name": "The macro offsetof shall not be used", + "precision": "very-high", + "severity": "error", + "short_name": "MacroOffsetofShallNotBeUsed", + "shared_implementation_short_name": "MacroOffsetofUsed", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "The macro offsetof shall not be used" + }, + "RULE-21-6-4": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "If a project defines the unsized version of a global operator delete, then the sized version shall be defined.", + "kind": "problem", + "name": "Sized 'operator delete' must be defined globally if unsized 'operator delete' is defined globally", + "precision": "very-high", + "severity": "error", + "short_name": "GlobalSizedOperatorDeleteShallBeDefined", + "shared_implementation_short_name": "GlobalSizedOperatorDeleteNotDefined", + "tags": [ + "maintainability", + "scope/system" + ] + }, + { + "description": "If a project defines the sized version of a global operator delete, then the unsized version shall be defined.", + "kind": "problem", + "name": "Unsized 'operator delete' must be defined globally if sized 'operator delete' is defined globally", + "precision": "very-high", + "severity": "error", + "short_name": "GlobalUnsizedOperatorDeleteShallBeDefined", + "shared_implementation_short_name": "GlobalUnsizedOperatorDeleteNotDefined", + "tags": [ + "maintainability", + "scope/system" + ] + } + ], + "title": "If a project defines either a sized or unsized version of a global operator delete, then both shall be defined" + }, + "RULE-26-3-1": { + "properties": { + "enforcement": "decidable", + "obligation": "advisory" + }, + "queries": [ + { + "description": "std::vector should not be specialized with bool.", + "kind": "problem", + "name": "std::vector should not be specialized with bool", + "precision": "very-high", + "severity": "error", + "short_name": "VectorShouldNotBeSpecializedWithBool", + "shared_implementation_short_name": "VectorShouldNotBeSpecializedWithBool", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "std::vector should not be specialized with bool" + }, + "RULE-28-6-2": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "Forwarding references and std::forward shall be used together.", + "kind": "problem", + "name": "Forwarding references and std::forward shall be used together", + "precision": "very-high", + "severity": "error", + "short_name": "ForwardingReferencesAndForwardNotUsedTogether", + "shared_implementation_short_name": "ForwardingReferencesAndForwardNotUsedTogether", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "Forwarding references and std::forward shall be used together" + }, + "RULE-30-0-1": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "The C Library input/output functions shall not be used.", + "kind": "problem", + "name": "The stream input/output library functions shall not be used", + "precision": "very-high", + "severity": "warning", + "short_name": "CstdioFunctionsShallNotBeUsed", + "shared_implementation_short_name": "CstdioFunctionsUsed", + "tags": [ + "maintainability", + "correctness", + "scope/single-translation-unit" + ] + }, + { + "description": "The C Library input/output functions shall not be used.", + "kind": "problem", + "name": "The stream input/output library macros shall not be used", + "precision": "very-high", + "severity": "warning", + "short_name": "CstdioMacrosShallNotBeUsed", + "shared_implementation_short_name": "CstdioMacrosUsed", + "tags": [ + "maintainability", + "correctness", + "scope/single-translation-unit" + ] + }, + { + "description": "The C Library input/output functions shall not be used.", + "kind": "problem", + "name": "The stream input/output library types shall not be used", + "precision": "very-high", + "severity": "warning", + "short_name": "CstdioTypesShallNotBeUsed", + "shared_implementation_short_name": "CstdioTypesUsed", + "tags": [ + "maintainability", + "correctness", + "scope/single-translation-unit" + ] + } + ], + "title": "The C Library input/output functions shall not be used" + }, + "RULE-5-13-1": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "In character literals and non-raw string literals, \\ shall only be used to form a defined escape sequence or universal character name.", + "kind": "problem", + "name": "In character literals and non-raw string literals, \\ shall only be used to form a defined escape", + "precision": "very-high", + "severity": "error", + "short_name": "BackslashCharacterMisuse", + "shared_implementation_short_name": "BackslashCharacterMisuse", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "In character literals and non-raw string literals, \\ shall only be used to form a defined escape sequence or universal character name" + }, + "RULE-5-13-2": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "Octal escape sequences, hexadecimal escape sequences, and universal character names shall be terminated.", + "kind": "problem", + "name": "Octal escape sequences, hexadecimal escape sequences, and universal character names shall be", + "precision": "very-high", + "severity": "error", + "short_name": "NonTerminatedEscapeSequences", + "shared_implementation_short_name": "NonTerminatedEscapeSequences", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "Octal escape sequences, hexadecimal escape sequences, and universal character names shall be terminated" + }, + "RULE-5-13-3": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "Octal constants shall not be used.", + "kind": "problem", + "name": "Octal constants shall not be used", + "precision": "very-high", + "severity": "error", + "short_name": "OctalConstantsUsed", + "shared_implementation_short_name": "UseOfNonZeroOctalLiteral", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "Octal constants shall not be used" + }, + "RULE-5-13-4": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "Unsigned integer literals shall be appropriately suffixed.", + "kind": "problem", + "name": "Unsigned integer literals shall be appropriately suffixed", + "precision": "very-high", + "severity": "error", + "short_name": "UnsignedIntegerLiteralsNotAppropriatelySuffixed", + "shared_implementation_short_name": "UnsignedIntegerLiteralsNotAppropriatelySuffixed", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "Unsigned integer literals shall be appropriately suffixed" + }, + "RULE-5-13-5": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "The lowercase form of L shall not be used as the first character in a literal suffix.", + "kind": "problem", + "name": "The lowercase form of L shall not be used as the first character in a literal suffix", + "precision": "very-high", + "severity": "error", + "short_name": "LowercaseLStartsInLiteralSuffix", + "shared_implementation_short_name": "LowercaseLStartsInLiteralSuffix", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "The lowercase form of L shall not be used as the first character in a literal suffix" + }, + "RULE-5-7-1": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "The character sequence /* shall not be used within a C-style comment.", + "kind": "problem", + "name": "The character sequence /* shall not be used within a C-style comment", + "precision": "very-high", + "severity": "error", + "short_name": "CharacterSequenceUsedWithinACStyleComment", + "shared_implementation_short_name": "CharacterSequenceUsedWithinACStyleComment", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "The character sequence /* shall not be used within a C-style comment" + }, + "RULE-5-7-3": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "Line-splicing shall not be used in // comments.", + "kind": "problem", + "name": "Line-splicing shall not be used in // comments", + "precision": "very-high", + "severity": "error", + "short_name": "LineSplicingUsedInComments", + "shared_implementation_short_name": "LineSplicingUsedInComments", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "Line-splicing shall not be used in // comments" + }, + "RULE-6-0-3": { + "properties": { + "enforcement": "decidable", + "obligation": "advisory" + }, + "queries": [ + { + "description": "The only declarations in the global namespace should be main, namespace declarations and extern \"C\" declarations.", + "kind": "problem", + "name": "The only declarations in the global namespace should be main, namespace declarations and extern \"C\"", + "precision": "very-high", + "severity": "error", + "short_name": "GlobalNamespaceDeclarations", + "shared_implementation_short_name": "GlobalNamespaceDeclarations", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "The only declarations in the global namespace should be main, namespace declarations and extern \"C\" declarations" + }, + "RULE-6-0-4": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "The identifier main shall not be used for a function other than the global function main.", + "kind": "problem", + "name": "The identifier main shall not be used for a function other than the global function main", + "precision": "very-high", + "severity": "error", + "short_name": "NonGlobalFunctionMain", + "shared_implementation_short_name": "NonGlobalFunctionMain", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "The identifier main shall not be used for a function other than the global function main" + }, + "RULE-6-4-2": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "A non-overriding member function definition that hides an inherited member function can result in unexpected behavior.", + "kind": "problem", + "name": "Member function hides inherited member function", + "precision": "very-high", + "severity": "error", + "short_name": "InheritedNonOverridableMemberFunction", + "shared_implementation_short_name": "HiddenInheritedNonOverridableMemberFunction", + "tags": [ + "correctness", + "scope/single-translation-unit" + ] + }, + { + "description": "An overriding member function definition thats hides an overload of the overridden inherited member function can result in unexpected behavior.", + "kind": "problem", + "name": "Member function hides inherited member function", + "precision": "very-high", + "severity": "error", + "short_name": "InheritedOverridableMemberFunction", + "shared_implementation_short_name": "HiddenInheritedOverridableMemberFunction", + "tags": [ + "correctness", + "scope/single-translation-unit" + ] + }, + { + "description": "A using declaration that makes a symbol available for unqualified lookup does not included definitions defined after the using declaration which can result in unexpected behavior.", + "kind": "problem", + "name": "Using declaration followed by new definition", + "precision": "very-high", + "severity": "error", + "short_name": "DefinitionShallBeConsideredForUnqualifiedLookup", + "shared_implementation_short_name": "DefinitionNotConsideredForUnqualifiedLookup", + "tags": [ + "correctness", + "scope/single-translation-unit" + ] + } + ], + "title": "Derived classes shall not conceal functions that are inherited from their bases" + }, + "RULE-6-4-3": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "Not using a qualified-id or `this->` syntax for identifiers used in a class template makes the code more difficult to understand.", + "kind": "problem", + "name": "In a class template with a dependent base, any name that may be found in that dependent base shall shall be referred to using a qualified-id or this->", + "precision": "very-high", + "severity": "warning", + "short_name": "NameShallBeReferredUsingAQualifiedIdOrThis", + "shared_implementation_short_name": "NameNotReferredUsingAQualifiedIdOrThis", + "tags": [ + "maintainability", + "readability", + "scope/single-translation-unit" + ] + }, + { + "description": "Not using a qualified-id or `this->` syntax for identifiers used in a class template makes the code more difficult to understand.", + "kind": "problem", + "name": "(Audit) In a class template with a dependent base, any name that may be found in that dependent base shall shall be referred to using a qualified-id or this->", + "precision": "very-high", + "severity": "warning", + "short_name": "NameShallBeReferredUsingAQualifiedIdOrThisAudit", + "shared_implementation_short_name": "NameNotReferredUsingAQualifiedIdOrThisAudit", + "tags": [ + "maintainability", + "readability", + "scope/single-translation-unit" + ] + } + ], + "title": "A name that is present in a dependent base shall not be resolved by unqualified lookup" + }, + "RULE-6-8-2": { + "properties": { + "enforcement": "decidable", + "obligation": "mandatory" + }, + "queries": [ + { + "description": "A function must not return a reference or a pointer to a local variable with automatic storage duration.", + "kind": "problem", + "name": "A function must not return a reference or a pointer to a local variable with automatic storage", + "precision": "very-high", + "severity": "error", + "short_name": "ReturnReferenceOrPointerToAutomaticLocalVariable", + "shared_implementation_short_name": "ReturnReferenceOrPointerToAutomaticLocalVariable", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "A function must not return a reference or a pointer to a local variable with automatic storage duration" + }, + "RULE-7-11-1": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "nullptr shall be the only form of the null-pointer-constant.", + "kind": "problem", + "name": "nullptr shall be the only form of the null-pointer-constant", + "precision": "very-high", + "severity": "error", + "short_name": "NullptrNotTheOnlyFormOfTheNullPointerConstant", + "shared_implementation_short_name": "NullptrNotTheOnlyFormOfTheNullPointerConstant", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "nullptr shall be the only form of the null-pointer-constant" + }, + "RULE-7-11-2": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "An array passed as a function argument shall not decay to a pointer.", + "kind": "problem", + "name": "An array passed as a function argument shall not decay to a pointer", + "precision": "very-high", + "severity": "error", + "short_name": "ArrayPassedAsFunctionArgumentDecayToAPointer", + "shared_implementation_short_name": "ArrayPassedAsFunctionArgumentDecayToAPointer", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "An array passed as a function argument shall not decay to a pointer" + }, + "RULE-8-18-2": { + "properties": { + "enforcement": "decidable", + "obligation": "advisory" + }, + "queries": [ + { + "description": "The result of an assignment operator should not be used.", + "kind": "problem", + "name": "The result of an assignment operator should not be used", + "precision": "very-high", + "severity": "error", + "short_name": "ResultOfAnAssignmentOperatorShouldNotBeUsed", + "shared_implementation_short_name": "ResultOfAnAssignmentOperatorShouldNotBeUsed", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "The result of an assignment operator should not be used" + }, + "RULE-8-2-10": { + "properties": { + "enforcement": "undecidable", + "obligation": "required" + }, + "queries": [ + { + "description": "Functions shall not call themselves, either directly or indirectly.", + "kind": "problem", + "name": "Functions shall not call themselves, either directly or indirectly", + "precision": "very-high", + "severity": "error", + "short_name": "FunctionsCallThemselvesEitherDirectlyOrIndirectly", + "shared_implementation_short_name": "FunctionsCallThemselvesEitherDirectlyOrIndirectly", + "tags": [ + "scope/system" + ] + } + ], + "title": "Functions shall not call themselves, either directly or indirectly" + }, + "RULE-8-2-4": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "Casts shall not be performed between a pointer to function and any other type.", + "kind": "problem", + "name": "Casts shall not be performed between a pointer to function and any other type", + "precision": "very-high", + "severity": "error", + "short_name": "CastsBetweenAPointerToFunctionAndAnyOtherType", + "shared_implementation_short_name": "CastsBetweenAPointerToFunctionAndAnyOtherType", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "Casts shall not be performed between a pointer to function and any other type" + }, + "RULE-8-2-5": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "reinterpret_cast shall not be used.", + "kind": "problem", + "name": "reinterpret_cast shall not be used", + "precision": "very-high", + "severity": "error", + "short_name": "ReinterpretCastShallNotBeUsed", + "shared_implementation_short_name": "ReinterpretCastUsed", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "reinterpret_cast shall not be used" + }, + "RULE-8-20-1": { + "properties": { + "enforcement": "decidable", + "obligation": "advisory" + }, + "queries": [ + { + "description": "An unsigned arithmetic operation with constant operands should not wrap.", + "kind": "problem", + "name": "An unsigned arithmetic operation with constant operands should not wrap", + "precision": "very-high", + "severity": "error", + "short_name": "UnsignedOperationWithConstantOperandsWraps", + "shared_implementation_short_name": "UnsignedOperationWithConstantOperandsWraps", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "An unsigned arithmetic operation with constant operands should not wrap" + }, + "RULE-8-3-1": { + "properties": { + "enforcement": "decidable", + "obligation": "advisory" + }, + "queries": [ + { + "description": "The built-in unary - operator should not be applied to an expression of unsigned type.", + "kind": "problem", + "name": "The built-in unary - operator should not be applied to an expression of unsigned type", + "precision": "very-high", + "severity": "error", + "short_name": "BuiltInUnaryOperatorAppliedToUnsignedExpression", + "shared_implementation_short_name": "BuiltInUnaryOperatorAppliedToUnsignedExpression", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "The built-in unary - operator should not be applied to an expression of unsigned type" + }, + "RULE-9-3-1": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "If the body of a switch is not enclosed in braces, then this can lead to incorrect execution, and hard for developers to maintain.", + "kind": "problem", + "name": "The statement forming the body of a switch shall be a compound statement", + "precision": "very-high", + "severity": "recommendation", + "short_name": "SwitchBodyCompoundCondition", + "shared_implementation_short_name": "SwitchCompoundCondition", + "tags": [ + "maintainability", + "readability", + "scope/single-translation-unit" + ] + }, + { + "description": "If the body of a loop is not enclosed in braces, then this can lead to incorrect execution, and hard for developers to maintain.", + "kind": "problem", + "name": "The statement forming the body of a loop shall be a compound statement", + "precision": "very-high", + "severity": "recommendation", + "short_name": "LoopBodyCompoundCondition", + "shared_implementation_short_name": "LoopCompoundCondition", + "tags": [ + "maintainability", + "readability", + "scope/single-translation-unit" + ] + } + ], + "title": "The body of an iteration-statement or a selection-statement shall be a compound-statement" + }, + "RULE-9-6-1": { + "properties": { + "enforcement": "decidable", + "obligation": "advisory" + }, + "queries": [ + { + "description": "The goto statement should not be used.", + "kind": "problem", + "name": "The goto statement should not be used", + "precision": "very-high", + "severity": "error", + "short_name": "GotoStatementShouldNotBeUsed", + "shared_implementation_short_name": "GotoStatementShouldNotBeUsed", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "The goto statement should not be used" + }, + "RULE-9-6-2": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "A goto statement shall reference a label in a surrounding block.", + "kind": "problem", + "name": "A goto statement shall reference a label in a surrounding block", + "precision": "very-high", + "severity": "error", + "short_name": "GotoReferenceALabelInSurroundingBlock", + "shared_implementation_short_name": "GotoReferenceALabelInSurroundingBlock", + "tags": [ + "scope/single-translation-unit" + ] + } + ], + "title": "A goto statement shall reference a label in a surrounding block" } } } \ No newline at end of file diff --git a/rule_packages/cpp/Inheritance.json b/rule_packages/cpp/Inheritance.json index 55175e0013..efc241a8e6 100644 --- a/rule_packages/cpp/Inheritance.json +++ b/rule_packages/cpp/Inheritance.json @@ -145,6 +145,7 @@ "precision": "very-high", "severity": "warning", "short_name": "AccessibleBaseClassBothVirtualAndNonVirtualInHierarchy", + "shared_implementation_short_name": "VirtualAndNonVirtualClassInTheHierarchy", "tags": [] } ], @@ -187,6 +188,7 @@ "precision": "very-high", "severity": "error", "short_name": "DynamicTypeOfThisUsedFromConstructorOrDestructor", + "shared_implementation_short_name": "ObjectsDynamicTypeUsedFromConstructorOrDestructor", "tags": [] } ], diff --git a/rule_packages/cpp/Initialization.json b/rule_packages/cpp/Initialization.json index da2ed53c98..3ca901a865 100644 --- a/rule_packages/cpp/Initialization.json +++ b/rule_packages/cpp/Initialization.json @@ -16,6 +16,7 @@ "precision": "very-high", "severity": "warning", "short_name": "ExplicitConstructorBaseClassInitialization", + "shared_implementation_short_name": "InitializeAllVirtualBaseClasses", "tags": [ "maintainability", "correctness" @@ -304,6 +305,7 @@ "precision": "very-high", "severity": "recommendation", "short_name": "ConfusingUseOfInitializerListConstructors", + "shared_implementation_short_name": "InitializerListConstructorIsTheOnlyConstructor", "tags": [ "readability", "maintainability" @@ -328,6 +330,7 @@ "precision": "very-high", "severity": "recommendation", "short_name": "MultipleLocalDeclarators", + "shared_implementation_short_name": "MultipleLocalDeclarators", "tags": [ "readability", "maintainability" @@ -340,6 +343,7 @@ "precision": "medium", "severity": "recommendation", "short_name": "MultipleGlobalOrMemberDeclarators", + "shared_implementation_short_name": "MultipleGlobalOrMemberDeclarators", "tags": [ "readability", "maintainability" diff --git a/rule_packages/cpp/Literals.json b/rule_packages/cpp/Literals.json index e762a9c411..7721b7dd6a 100644 --- a/rule_packages/cpp/Literals.json +++ b/rule_packages/cpp/Literals.json @@ -39,6 +39,7 @@ "precision": "very-high", "severity": "error", "short_name": "EscapeSequenceOutsideISO", + "shared_implementation_short_name": "BackslashCharacterMisuse", "tags": [ "correctness" ] @@ -85,6 +86,7 @@ "precision": "very-high", "severity": "recommendation", "short_name": "NullPointerConstantNotNullptr", + "shared_implementation_short_name": "NullptrNotTheOnlyFormOfTheNullPointerConstant", "tags": [ "readability" ] @@ -132,6 +134,7 @@ "precision": "very-high", "severity": "recommendation", "short_name": "UseOfNonZeroOctalLiteral", + "shared_implementation_short_name": "UseOfNonZeroOctalLiteral", "tags": [ "readability" ] @@ -166,6 +169,7 @@ "precision": "very-high", "severity": "warning", "short_name": "MissingUSuffix", + "shared_implementation_short_name": "UnsignedIntegerLiteralsNotAppropriatelySuffixed", "tags": [ "correctness", "readability" diff --git a/rule_packages/cpp/MoveForward.json b/rule_packages/cpp/MoveForward.json index 6278135d2c..b7e47116f1 100644 --- a/rule_packages/cpp/MoveForward.json +++ b/rule_packages/cpp/MoveForward.json @@ -40,6 +40,7 @@ "precision": "very-high", "severity": "error", "short_name": "ForwardingValuesToOtherFunctions", + "shared_implementation_short_name": "ForwardingReferencesAndForwardNotUsedTogether", "tags": [ "correctness" ] diff --git a/rule_packages/cpp/Naming.json b/rule_packages/cpp/Naming.json index e59f007975..441979c3c9 100644 --- a/rule_packages/cpp/Naming.json +++ b/rule_packages/cpp/Naming.json @@ -290,7 +290,7 @@ "precision": "very-high", "severity": "recommendation", "short_name": "DifferentIdentifiersNotTypographicallyUnambiguous", - "shared_implementation_short_name" : "DifferentIdentifiersNotTypographicallyUnambiguous", + "shared_implementation_short_name": "DifferentIdentifiersNotTypographicallyUnambiguous", "tags": [ "readability", "maintainability" @@ -314,6 +314,7 @@ "precision": "very-high", "severity": "warning", "short_name": "IdentifierMainUsedForAFunctionOtherThanTheGlobalFunctionMain", + "shared_implementation_short_name": "NonGlobalFunctionMain", "tags": [ "maintainability", "readability" diff --git a/rule_packages/cpp/OperatorInvariants.json b/rule_packages/cpp/OperatorInvariants.json index b34df998e9..8ba76cd0f7 100644 --- a/rule_packages/cpp/OperatorInvariants.json +++ b/rule_packages/cpp/OperatorInvariants.json @@ -39,6 +39,7 @@ "precision": "very-high", "severity": "error", "short_name": "CopyAssignmentAndAMoveHandleSelfAssignment", + "shared_implementation_short_name": "CopyAndMoveAssignmentsShallHandleSelfAssignment", "tags": [ "correctness" ] diff --git a/rule_packages/cpp/Operators.json b/rule_packages/cpp/Operators.json index 8bb2cb9d55..76be8a732a 100644 --- a/rule_packages/cpp/Operators.json +++ b/rule_packages/cpp/Operators.json @@ -297,6 +297,7 @@ "precision": "very-high", "severity": "error", "short_name": "UnaryMinusOperatorAppliedToAnExpressionWhoseUnderlyingTypeIsUnsigned", + "shared_implementation_short_name": "BuiltInUnaryOperatorAppliedToUnsignedExpression", "tags": [] } ], @@ -318,6 +319,7 @@ "precision": "very-high", "severity": "error", "short_name": "UnaryOperatorOverloaded", + "shared_implementation_short_name": "AddressOfOperatorOverloaded", "tags": [] } ], diff --git a/rule_packages/cpp/Pointers.json b/rule_packages/cpp/Pointers.json index 6a862e057c..b6a0aaef09 100644 --- a/rule_packages/cpp/Pointers.json +++ b/rule_packages/cpp/Pointers.json @@ -87,6 +87,7 @@ "precision": "very-high", "severity": "error", "short_name": "PointerToMemberVirtualFunctionWithNullPointerConstant", + "shared_implementation_short_name": "PotentiallyVirtualPointerOnlyComparesToNullptr", "tags": [ "correctness" ] @@ -279,6 +280,7 @@ "precision": "very-high", "severity": "warning", "short_name": "IdentifierWithArrayTypePassedAsFunctionArgumentDecayToAPointer", + "shared_implementation_short_name": "ArrayPassedAsFunctionArgumentDecayToAPointer", "tags": [ "correctness" ] @@ -325,6 +327,7 @@ "precision": "very-high", "severity": "error", "short_name": "CastNotConvertPointerToFunction", + "shared_implementation_short_name": "CastsBetweenAPointerToFunctionAndAnyOtherType", "tags": [ "correctness" ] diff --git a/rule_packages/cpp/Representation.json b/rule_packages/cpp/Representation.json index 96674eef0e..c87094ea4b 100644 --- a/rule_packages/cpp/Representation.json +++ b/rule_packages/cpp/Representation.json @@ -96,6 +96,7 @@ "precision": "very-high", "severity": "error", "short_name": "NamedBitFieldsWithSignedIntegerTypeShallHaveALengthOfMoreThanOneBit", + "shared_implementation_short_name": "NamedBitFieldsWithSignedIntegerType", "tags": [ "correctness" ] diff --git a/rule_packages/cpp/Scope.json b/rule_packages/cpp/Scope.json index 30b92a0675..6677b8b81a 100644 --- a/rule_packages/cpp/Scope.json +++ b/rule_packages/cpp/Scope.json @@ -64,6 +64,7 @@ "precision": "very-high", "severity": "error", "short_name": "HiddenInheritedNonOverridableMemberFunction", + "shared_implementation_short_name": "HiddenInheritedNonOverridableMemberFunction", "tags": [ "correctness" ] @@ -75,6 +76,7 @@ "precision": "very-high", "severity": "error", "short_name": "HiddenInheritedOverridableMemberFunction", + "shared_implementation_short_name": "HiddenInheritedOverridableMemberFunction", "tags": [ "correctness" ] @@ -86,6 +88,7 @@ "precision": "very-high", "severity": "error", "short_name": "DefinitionNotConsideredForUnqualifiedLookup", + "shared_implementation_short_name": "DefinitionNotConsideredForUnqualifiedLookup", "tags": [ "correctness" ] @@ -228,6 +231,7 @@ "precision": "very-high", "severity": "warning", "short_name": "GlobalNamespaceMembershipViolation", + "shared_implementation_short_name": "GlobalNamespaceDeclarations", "tags": [ "readability" ] diff --git a/rule_packages/cpp/Templates.json b/rule_packages/cpp/Templates.json index 006f81bda6..a6520a7780 100644 --- a/rule_packages/cpp/Templates.json +++ b/rule_packages/cpp/Templates.json @@ -22,7 +22,7 @@ "readability" ] } - ], + ], "title": "A template should check if a specific template argument is suitable for this template." }, "A14-5-1": { @@ -112,6 +112,7 @@ "precision": "very-high", "severity": "warning", "short_name": "ExplicitSpecializationsOfFunctionTemplatesUsed", + "shared_implementation_short_name": "FunctionTemplatesExplicitlySpecialized", "tags": [ "maintainability", "readability" @@ -171,25 +172,27 @@ "precision": "very-high", "severity": "warning", "short_name": "NameNotReferredUsingAQualifiedIdOrThis", + "shared_implementation_short_name": "NameNotReferredUsingAQualifiedIdOrThis", "tags": [ "maintainability", "readability" ] }, { - "description": "Not using a qualified-id or `this->` syntax for identifiers used in a class template makes the code more difficult to understand.", - "kind": "problem", - "name": "(Audit) In a class template with a dependent base, any name that may be found in that dependent base shall shall be referred to using a qualified-id or this->", - "precision": "very-high", - "severity": "warning", - "short_name": "NameNotReferredUsingAQualifiedIdOrThisAudit", - "tags": [ - "maintainability", - "readability" - ] - } + "description": "Not using a qualified-id or `this->` syntax for identifiers used in a class template makes the code more difficult to understand.", + "kind": "problem", + "name": "(Audit) In a class template with a dependent base, any name that may be found in that dependent base shall shall be referred to using a qualified-id or this->", + "precision": "very-high", + "severity": "warning", + "short_name": "NameNotReferredUsingAQualifiedIdOrThisAudit", + "shared_implementation_short_name": "NameNotReferredUsingAQualifiedIdOrThisAudit", + "tags": [ + "maintainability", + "readability" + ] + } ], "title": "In a class template with a dependent base, any name that may be found in that dependent base shall be referred to using a qualified-id or this->." } } -} +} \ No newline at end of file diff --git a/rule_packages/cpp/VirtualFunctions.json b/rule_packages/cpp/VirtualFunctions.json index 198aba1bb7..eff4e15beb 100644 --- a/rule_packages/cpp/VirtualFunctions.json +++ b/rule_packages/cpp/VirtualFunctions.json @@ -177,6 +177,7 @@ "precision": "very-high", "severity": "warning", "short_name": "VirtualFunctionParametersUseTheSameDefaultArguments", + "shared_implementation_short_name": "OverridingShallSpecifyDifferentDefaultArguments", "tags": [ "correctness" ] diff --git a/rules.csv b/rules.csv index 63d45ac539..e494a82ea3 100644 --- a/rules.csv +++ b/rules.csv @@ -643,9 +643,9 @@ c,MISRA-C-2012,RULE-5-9,Yes,Advisory,,,Identifiers that define objects or functi c,MISRA-C-2012,RULE-6-1,Yes,Required,,,Bit-fields shall only be declared with an appropriate type,M9-6-4,BitfieldTypes,Medium, c,MISRA-C-2012,RULE-6-2,Yes,Required,,,Single-bit named bit fields shall not be of a signed type,M9-6-4,BitfieldTypes,Import, c,MISRA-C-2012,RULE-7-1,Yes,Required,,,Octal constants shall not be used,M2-13-2,Banned,Import, -c,MISRA-C-2012,RULE-7-2,Yes,Required,,,A �u� or �U� suffix shall be applied to all integer constants that are represented in an unsigned type,M2-13-3,Syntax,Easy, -c,MISRA-C-2012,RULE-7-3,Yes,Required,,,The lowercase character �l� shall not be used in a literal suffix,M2-13-4,Syntax,Easy, -c,MISRA-C-2012,RULE-7-4,Yes,Required,,,A string literal shall not be assigned to an object unless the object�s type is �pointer to const-qualified char�,A2-13-4,Types1,Easy, +c,MISRA-C-2012,RULE-7-2,Yes,Required,,,A 'u' or 'U' suffix shall be applied to all integer constants that are represented in an unsigned type,M2-13-3,Syntax,Easy, +c,MISRA-C-2012,RULE-7-3,Yes,Required,,,The lowercase character 'l' shall not be used in a literal suffix,M2-13-4,Syntax,Easy, +c,MISRA-C-2012,RULE-7-4,Yes,Required,,,A string literal shall not be assigned to an object unless the object's type is 'pointer to const-qualified char',A2-13-4,Types1,Easy, c,MISRA-C-2012,RULE-8-1,Yes,Required,,,Types shall be explicitly specified,,Declarations3,Medium, c,MISRA-C-2012,RULE-8-2,Yes,Required,,,Function types shall be in prototype form with named parameters,,Declarations4,Medium, c,MISRA-C-2012,RULE-8-3,Yes,Required,,,All declarations of an object or function shall use the same names and type qualifiers,M3-2-1,Declarations4,Medium, @@ -686,7 +686,7 @@ c,MISRA-C-2012,RULE-12-1,Yes,Advisory,,,The precedence of operators within expre c,MISRA-C-2012,RULE-12-2,Yes,Required,,,The right hand operand of a shift operator shall lie in the range zero to one less than the width in bits of the essential type of the left hand operand,,Contracts7,Medium, c,MISRA-C-2012,RULE-12-3,Yes,Advisory,,,The comma operator should not be used,M5-18-1,Banned,Import, c,MISRA-C-2012,RULE-12-4,Yes,Advisory,,,Evaluation of constant expressions should not lead to unsigned integer wrap-around,INT30-C,IntegerOverflow,Easy, -c,MISRA-C-2012,RULE-12-5,Yes,Mandatory,,,The sizeof operator shall not have an operand which is a function parameter declared as �array of type�,,Types1,Medium, +c,MISRA-C-2012,RULE-12-5,Yes,Mandatory,,,The sizeof operator shall not have an operand which is a function parameter declared as 'array of type',,Types1,Medium, c,MISRA-C-2012,RULE-13-1,Yes,Required,,,Initializer lists shall not contain persistent side effects,,SideEffects1,Medium, c,MISRA-C-2012,RULE-13-2,Yes,Required,,,The value of an expression and its persistent side effects shall be the same under all permitted evaluation orders,PRE31-C,SideEffects3,Medium, c,MISRA-C-2012,RULE-13-3,Yes,Advisory,,,A full expression containing an increment (++) or decrement (--) operator should have no other potential side effects other than that caused by the increment or decrement operator,,SideEffects2,Medium, @@ -787,36 +787,36 @@ cpp,MISRA-C++-2023,DIR-0-3-2,Yes,Required,,,A function call shall not violate th cpp,MISRA-C++-2023,RULE-4-1-1,Yes,Required,Undecidable,System,A program shall conform to ISO/IEC 14882:2017 (C++17),,,Hard, cpp,MISRA-C++-2023,RULE-4-1-2,Yes,Advisory,Decidable,Single Translation Unit,Deprecated features should not be used,,,Very Hard, cpp,MISRA-C++-2023,RULE-4-1-3,Yes,Required,Undecidable,System,There shall be no occurrence of undefined or critical unspecified behaviour,,,Very Hard, -cpp,MISRA-C++-2023,RULE-4-6-1,Yes,Required,Undecidable,System,Operations on a memory location shall be sequenced appropriately,RULE-13-2,,Import, +cpp,MISRA-C++-2023,RULE-4-6-1,Yes,Required,Undecidable,System,Operations on a memory location shall be sequenced appropriately,RULE-13-2,,Easy, cpp,MISRA-C++-2023,RULE-5-0-1,Yes,Advisory,Decidable,Single Translation Unit,Trigraph-like sequences should not be used,A2-5-1,,Very Hard, -cpp,MISRA-C++-2023,RULE-5-7-1,Yes,Required,Decidable,Single Translation Unit,The character sequence /* shall not be used within a C-style comment,M2-7-1,,Import, +cpp,MISRA-C++-2023,RULE-5-7-1,Yes,Required,Decidable,Single Translation Unit,The character sequence /* shall not be used within a C-style comment,M2-7-1,ImportMisra23,Import, cpp,MISRA-C++-2023,DIR-5-7-2,Yes,Advisory,,,Sections of code should not be “commented out”,A2-7-2,ImportMisra23,Import, -cpp,MISRA-C++-2023,RULE-5-7-3,Yes,Required,Decidable,Single Translation Unit,Line-splicing shall not be used in // comments,A2-7-1,,Import, +cpp,MISRA-C++-2023,RULE-5-7-3,Yes,Required,Decidable,Single Translation Unit,Line-splicing shall not be used in // comments,A2-7-1,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-5-10-1,Yes,Required,Decidable,Single Translation Unit,User-defined identifiers shall have an appropriate form,,,Easy, -cpp,MISRA-C++-2023,RULE-5-13-1,Yes,Required,Decidable,Single Translation Unit,"In character literals and non-raw string literals, \ shall only be used to form a defined escape sequence or universal character name",A2-13-1,,Import, -cpp,MISRA-C++-2023,RULE-5-13-2,Yes,Required,Decidable,Single Translation Unit,"Octal escape sequences, hexadecimal escape sequences, and universal character names shall be terminated",RULE-4-1,,Import, -cpp,MISRA-C++-2023,RULE-5-13-3,Yes,Required,Decidable,Single Translation Unit,Octal constants shall not be used,RULE-7-1,,Import, -cpp,MISRA-C++-2023,RULE-5-13-4,Yes,Required,Decidable,Single Translation Unit,Unsigned integer literals shall be appropriately suffixed,M2-13-3,,Import, -cpp,MISRA-C++-2023,RULE-5-13-5,Yes,Required,Decidable,Single Translation Unit,The lowercase form of L shall not be used as the first character in a literal suffix,RULE-7-3,,Import, +cpp,MISRA-C++-2023,RULE-5-13-1,Yes,Required,Decidable,Single Translation Unit,"In character literals and non-raw string literals, \ shall only be used to form a defined escape sequence or universal character name",A2-13-1,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-5-13-2,Yes,Required,Decidable,Single Translation Unit,"Octal escape sequences, hexadecimal escape sequences, and universal character names shall be terminated",RULE-4-1,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-5-13-3,Yes,Required,Decidable,Single Translation Unit,Octal constants shall not be used,M2-13-2,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-5-13-4,Yes,Required,Decidable,Single Translation Unit,Unsigned integer literals shall be appropriately suffixed,M2-13-3,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-5-13-5,Yes,Required,Decidable,Single Translation Unit,The lowercase form of L shall not be used as the first character in a literal suffix,RULE-7-3,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-5-13-6,Yes,Required,Decidable,Single Translation Unit,An integer-literal of type long long shall not use a single L or l in any suffix,,,Easy, cpp,MISRA-C++-2023,RULE-5-13-7,No,Required,Decidable,Single Translation Unit,String literals with different encoding prefixes shall not be concatenated,A2-13-2,,, cpp,MISRA-C++-2023,RULE-6-0-1,Yes,Required,Decidable,Single Translation Unit,Block scope declarations shall not be visually ambiguous,"M3-1-2,DCL53-CPP",,Easy, cpp,MISRA-C++-2023,RULE-6-0-2,Yes,Advisory,Decidable,Single Translation Unit,"When an array with external linkage is declared, its size should be explicitly specified",RULE-18-8,,Easy, -cpp,MISRA-C++-2023,RULE-6-0-3,Yes,Advisory,Decidable,Single Translation Unit,"The only declarations in the global namespace should be main, namespace declarations and extern ""C"" declarations",M7-3-1,,Import, -cpp,MISRA-C++-2023,RULE-6-0-4,Yes,Required,Decidable,Single Translation Unit,The identifier main shall not be used for a function other than the global function main,M7-3-2,,Import, +cpp,MISRA-C++-2023,RULE-6-0-3,Yes,Advisory,Decidable,Single Translation Unit,"The only declarations in the global namespace should be main, namespace declarations and extern ""C"" declarations",M7-3-1,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-6-0-4,Yes,Required,Decidable,Single Translation Unit,The identifier main shall not be used for a function other than the global function main,M7-3-2,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-6-2-1,Yes,Required,Decidable,System,The one-definition rule shall not be violated,M3-2-2,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-6-2-2,Yes,Required,Decidable,System,All declarations of a variable or function shall have the same type,"M3-9-1,DCL40-C",,Easy, cpp,MISRA-C++-2023,RULE-6-2-3,Yes,Required,Decidable,System,The source code used to implement an entity shall appear only once,,,Medium, cpp,MISRA-C++-2023,RULE-6-2-4,Yes,Required,Decidable,Single Translation Unit,A header file shall not contain definitions of functions or objects that are non-inline and have external linkage,,,Easy, cpp,MISRA-C++-2023,RULE-6-4-1,Yes,Required,Decidable,Single Translation Unit,A variable declared in an inner scope shall not hide a variable declared in an outer scope,A2-10-1,ImportMisra23,Import, -cpp,MISRA-C++-2023,RULE-6-4-2,Yes,Required,Decidable,Single Translation Unit,Derived classes shall not conceal functions that are inherited from their bases,A7-3-1,,Import, -cpp,MISRA-C++-2023,RULE-6-4-3,Yes,Required,Decidable,Single Translation Unit,A name that is present in a dependent base shall not be resolved by unqualified lookup,M14-6-1,,Import, +cpp,MISRA-C++-2023,RULE-6-4-2,Yes,Required,Decidable,Single Translation Unit,Derived classes shall not conceal functions that are inherited from their bases,A7-3-1,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-6-4-3,Yes,Required,Decidable,Single Translation Unit,A name that is present in a dependent base shall not be resolved by unqualified lookup,M14-6-1,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-6-5-1,Yes,Advisory,Decidable,Single Translation Unit,A function or object with external linkage should be introduced in a header file,,,Medium, cpp,MISRA-C++-2023,RULE-6-5-2,Yes,Advisory,Decidable,Single Translation Unit,Internal linkage should be specified appropriately,,,Medium, cpp,MISRA-C++-2023,RULE-6-7-1,Yes,Required,Decidable,Single Translation Unit,Local variables shall not have static storage duration,,,Easy, cpp,MISRA-C++-2023,RULE-6-7-2,Yes,Required,Decidable,Single Translation Unit,Global variables shall not be used,,,Easy, cpp,MISRA-C++-2023,RULE-6-8-1,Yes,Required,Undecidable,System,An object shall not be accessed outside of its lifetime,A3-8-1,ImportMisra23,Import, -cpp,MISRA-C++-2023,RULE-6-8-2,Yes,Mandatory,Decidable,Single Translation Unit,A function must not return a reference or a pointer to a local variable with automatic storage duration,M7-5-1,,Import, +cpp,MISRA-C++-2023,RULE-6-8-2,Yes,Mandatory,Decidable,Single Translation Unit,A function must not return a reference or a pointer to a local variable with automatic storage duration,M7-5-1,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-6-8-3,Yes,Required,Decidable,Single Translation Unit,An assignment operator shall not assign the address of an object with automatic storage duration to an object with a greater lifetime,,,Medium, cpp,MISRA-C++-2023,RULE-6-8-4,Yes,Advisory,Decidable,Single Translation Unit,Member functions returning references to their object should be refqualified appropriately,,,Medium, cpp,MISRA-C++-2023,RULE-6-9-1,Yes,Required,Decidable,Single Translation Unit,The same type aliases shall be used in all declarations of the same entity,,,Medium, @@ -827,8 +827,8 @@ cpp,MISRA-C++-2023,RULE-7-0-3,Yes,Required,Decidable,Single Translation Unit,The cpp,MISRA-C++-2023,RULE-7-0-4,Yes,Required,Decidable,Single Translation Unit,The operands of bitwise operators and shift operators shall be appropriate,RULE-10-1,,Medium, cpp,MISRA-C++-2023,RULE-7-0-5,Yes,Required,Decidable,Single Translation Unit,Integral promotion and the usual arithmetic conversions shall not change the signedness or the type category of an operand,"M5-0-4,M5-0-9,INT31-C",,Medium, cpp,MISRA-C++-2023,RULE-7-0-6,Yes,Required,Decidable,Single Translation Unit,Assignment between numeric types shall be appropriate,,,Hard, -cpp,MISRA-C++-2023,RULE-7-11-1,Yes,Required,Decidable,Single Translation Unit,nullptr shall be the only form of the null-pointer-constant,A4-10-1,,Import, -cpp,MISRA-C++-2023,RULE-7-11-2,Yes,Required,Decidable,Single Translation Unit,An array passed as a function argument shall not decay to a pointer,M5-2-12,,Import, +cpp,MISRA-C++-2023,RULE-7-11-1,Yes,Required,Decidable,Single Translation Unit,nullptr shall be the only form of the null-pointer-constant,A4-10-1,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-7-11-2,Yes,Required,Decidable,Single Translation Unit,An array passed as a function argument shall not decay to a pointer,M5-2-12,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-7-11-3,Yes,Required,Decidable,Single Translation Unit,A conversion from function type to pointer-to-function type shall only occur in appropriate contexts,,,Easy, cpp,MISRA-C++-2023,RULE-8-0-1,Yes,Advisory,Decidable,Single Translation Unit,Parentheses should be used to make the meaning of an expression appropriately explicit,M5-0-2,,Medium, cpp,MISRA-C++-2023,RULE-8-1-1,Yes,Required,Decidable,Single Translation Unit,A non-transient lambda shall not implicitly capture this,,,Easy, @@ -836,81 +836,81 @@ cpp,MISRA-C++-2023,RULE-8-1-2,Yes,Advisory,Decidable,Single Translation Unit,Var cpp,MISRA-C++-2023,RULE-8-2-1,Yes,Required,Decidable,Single Translation Unit,A virtual base class shall only be cast to a derived class by means of dynamic_cast,,,Easy, cpp,MISRA-C++-2023,RULE-8-2-2,Yes,Required,Decidable,Single Translation Unit,C-style casts and functional notation casts shall not be used,A5-2-2,,Easy, cpp,MISRA-C++-2023,RULE-8-2-3,Yes,Required,Decidable,Single Translation Unit,A cast shall not remove any const or volatile qualification from the type accessed via a pointer or by reference,A5-2-3,ImportMisra23,Import, -cpp,MISRA-C++-2023,RULE-8-2-4,Yes,Required,Decidable,Single Translation Unit,Casts shall not be performed between a pointer to function and any other type,M5-2-6,,Import, -cpp,MISRA-C++-2023,RULE-8-2-5,Yes,Required,Decidable,Single Translation Unit,reinterpret_cast shall not be used,A5-2-4,,Import, +cpp,MISRA-C++-2023,RULE-8-2-4,Yes,Required,Decidable,Single Translation Unit,Casts shall not be performed between a pointer to function and any other type,M5-2-6,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-8-2-5,Yes,Required,Decidable,Single Translation Unit,reinterpret_cast shall not be used,A5-2-4,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-8-2-6,Yes,Required,Decidable,Single Translation Unit,"An object with integral, enumerated, or pointer to void type shall not be cast to a pointer type","RULE-11-6, INT36-C",,Easy, cpp,MISRA-C++-2023,RULE-8-2-7,Yes,Advisory,Decidable,Single Translation Unit,A cast should not convert a pointer type to an integral type,"RULE-11-6, INT36-C",,Easy, cpp,MISRA-C++-2023,RULE-8-2-8,Yes,Required,Decidable,Single Translation Unit,An object pointer type shall not be cast to an integral type other than std::uintptr_t or std::intptr_t,"RULE-11-6, INT36-C",,Easy, cpp,MISRA-C++-2023,RULE-8-2-9,Yes,Required,Decidable,Single Translation Unit,The operand to typeid shall not be an expression of polymorphic class type,,,Easy, -cpp,MISRA-C++-2023,RULE-8-2-10,Yes,Required,Undecidable,System,"Functions shall not call themselves, either directly or indirectly",A7-5-2,,Import, +cpp,MISRA-C++-2023,RULE-8-2-10,Yes,Required,Undecidable,System,"Functions shall not call themselves, either directly or indirectly",A7-5-2,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-8-2-11,Yes,Required,Decidable,Single Translation Unit,An argument passed via ellipsis shall have an appropriate type,,,Easy, -cpp,MISRA-C++-2023,RULE-8-3-1,Yes,Advisory,Decidable,Single Translation Unit,The built-in unary - operator should not be applied to an expression of unsigned type,M5-3-2,,Import, +cpp,MISRA-C++-2023,RULE-8-3-1,Yes,Advisory,Decidable,Single Translation Unit,The built-in unary - operator should not be applied to an expression of unsigned type,M5-3-2,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-8-3-2,Yes,Advisory,Decidable,Single Translation Unit,The built-in unary + operator should not be used,,,Easy, cpp,MISRA-C++-2023,RULE-8-7-1,Yes,Required,Undecidable,System,Pointer arithmetic shall not form an invalid pointer,ARR30-C,,Easy, cpp,MISRA-C++-2023,RULE-8-7-2,Yes,Required,Undecidable,System,Subtraction between pointers shall only be applied to pointers that address elements of the same array,ARR36-C,,Easy, cpp,MISRA-C++-2023,RULE-8-9-1,Yes,Required,Undecidable,System,"The built-in relational operators >, >=, < and <= shall not be applied to objects of pointer type, except where they point to elements of the same array",ARR36-C,,Easy, cpp,MISRA-C++-2023,RULE-8-14-1,Yes,Advisory,Undecidable,System,The right-hand operand of a logical && or operator should not contain persistent side effects,"M5-14-1, RULE-13-5",,Medium, cpp,MISRA-C++-2023,RULE-8-18-1,Yes,Mandatory,Undecidable,System,An object or subobject must not be copied to an overlapping object,"M0-2-1, RULE-19-1",,Hard, -cpp,MISRA-C++-2023,RULE-8-18-2,Yes,Advisory,Decidable,Single Translation Unit,The result of an assignment operator should not be used,RULE-13-4,,Import, -cpp,MISRA-C++-2023,RULE-8-19-1,Yes,Advisory,Decidable,Single Translation Unit,The comma operator should not be used,M15-8-1,,Import, -cpp,MISRA-C++-2023,RULE-8-20-1,Yes,Advisory,Decidable,Single Translation Unit,An unsigned arithmetic operation with constant operands should not wrap,INT30-C,,Import, +cpp,MISRA-C++-2023,RULE-8-18-2,Yes,Advisory,Decidable,Single Translation Unit,The result of an assignment operator should not be used,RULE-13-4,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-8-19-1,Yes,Advisory,Decidable,Single Translation Unit,The comma operator should not be used,M5-18-1,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-8-20-1,Yes,Advisory,Decidable,Single Translation Unit,An unsigned arithmetic operation with constant operands should not wrap,INT30-C,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-9-2-1,Yes,Required,Decidable,Single Translation Unit,An explicit type conversion shall not be an expression statement,DCL53-CPP,,Easy, -cpp,MISRA-C++-2023,RULE-9-3-1,Yes,Required,Decidable,Single Translation Unit,The body of an iteration-statement or a selection-statement shall be a compound-statement,RULE-15-6,,Import, +cpp,MISRA-C++-2023,RULE-9-3-1,Yes,Required,Decidable,Single Translation Unit,The body of an iteration-statement or a selection-statement shall be a compound-statement,RULE-15-6,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-9-4-1,Yes,Required,Decidable,Single Translation Unit,All if ... else if constructs shall be terminated with an else statement,RULE-15-7,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-9-4-2,Yes,Required,Decidable,Single Translation Unit,The structure of a switch statement shall be appropriate,"RULE-16-1, RULE-16-2,RULE-16-3,RULE-16-4,RULE-16-5,RULE-16-6,RULE-16-7",,Medium, cpp,MISRA-C++-2023,RULE-9-5-1,Yes,Advisory,Decidable,Single Translation Unit,Legacy for statements should be simple,,,Hard, cpp,MISRA-C++-2023,RULE-9-5-2,Yes,Required,Decidable,Single Translation Unit,A for-range-initializer shall contain at most one function call,,,Easy, -cpp,MISRA-C++-2023,RULE-9-6-1,Yes,Advisory,Decidable,Single Translation Unit,The goto statement should not be used,RULE-15-1,,Import, -cpp,MISRA-C++-2023,RULE-9-6-2,Yes,Required,Decidable,Single Translation Unit,A goto statement shall reference a label in a surrounding block,RULE-15-3,,Import, +cpp,MISRA-C++-2023,RULE-9-6-1,Yes,Advisory,Decidable,Single Translation Unit,The goto statement should not be used,RULE-15-1,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-9-6-2,Yes,Required,Decidable,Single Translation Unit,A goto statement shall reference a label in a surrounding block,RULE-15-3,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-9-6-3,Yes,Required,Decidable,Single Translation Unit,The goto statement shall jump to a label declared later in the function body,RULE-15-2,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-9-6-4,Yes,Required,Undecidable,System,A function declared with the [[noreturn]] attribute shall not return,MSC53-CPP,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-9-6-5,Yes,Required,Decidable,Single Translation Unit,A function with non-void return type shall return a value on all paths,MSC52-CPP,ImportMisra23,Import, -cpp,MISRA-C++-2023,RULE-10-0-1,Yes,Advisory,Decidable,Single Translation Unit,A declaration should not declare more than one variable or member variable,M8-0-1,,Import, +cpp,MISRA-C++-2023,RULE-10-0-1,Yes,Advisory,Decidable,Single Translation Unit,A declaration should not declare more than one variable or member variable,M8-0-1,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-10-1-1,Yes,Advisory,Decidable,Single Translation Unit,The target type of a pointer or lvalue reference parameter should be const-qualified appropriately,RULE-8-13,,Hard, cpp,MISRA-C++-2023,RULE-10-1-2,Yes,Required,Decidable,Single Translation Unit,The volatile qualifier shall be used appropriately,,,Easy, -cpp,MISRA-C++-2023,RULE-10-2-1,Yes,Required,Decidable,Single Translation Unit,An enumeration shall be defined with an explicit underlying type,A7-2-2,,Import, +cpp,MISRA-C++-2023,RULE-10-2-1,Yes,Required,Decidable,Single Translation Unit,An enumeration shall be defined with an explicit underlying type,A7-2-2,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-10-2-2,Yes,Advisory,Decidable,Single Translation Unit,Unscoped enumerations should not be declared,A7-2-3,,Easy, cpp,MISRA-C++-2023,RULE-10-2-3,Yes,Required,Decidable,Single Translation Unit,The numeric value of an unscoped enumeration with no fixed underlying type shall not be used,A4-5-1,,Easy, cpp,MISRA-C++-2023,RULE-10-3-1,Yes,Advisory,Decidable,Single Translation Unit,There should be no unnamed namespaces in header files,"DCL59-CPP, M7-3-3",,Easy, -cpp,MISRA-C++-2023,RULE-10-4-1,Yes,Required,Decidable,Single Translation Unit,The asm declaration shall not be used,A7-4-1,,Import, +cpp,MISRA-C++-2023,RULE-10-4-1,Yes,Required,Decidable,Single Translation Unit,The asm declaration shall not be used,A7-4-1,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-11-3-1,Yes,Advisory,Decidable,Single Translation Unit,Variables of array type should not be declared,,,Easy, cpp,MISRA-C++-2023,RULE-11-3-2,Yes,Advisory,Decidable,Single Translation Unit,The declaration of an object should contain no more than two levels of pointer indirection,A5-0-3,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-11-6-1,Yes,Advisory,Decidable,Single Translation Unit,All variables should be initialized,,,Easy, cpp,MISRA-C++-2023,RULE-11-6-2,Yes,Mandatory,Undecidable,System,The value of an object must not be read before it has been set,A8-5-0,,Very Hard, -cpp,MISRA-C++-2023,RULE-11-6-3,Yes,Required,Decidable,Single Translation Unit,"Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique",RULE-8-12,,Import, +cpp,MISRA-C++-2023,RULE-11-6-3,Yes,Required,Decidable,Single Translation Unit,"Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique",RULE-8-12,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-12-2-1,Yes,Advisory,Decidable,Single Translation Unit,Bit-fields should not be declared,A9-6-2,,Easy, -cpp,MISRA-C++-2023,RULE-12-2-2,Yes,Required,Decidable,Single Translation Unit,A bit-field shall have an appropriate type,RULE-6-1,,Import, -cpp,MISRA-C++-2023,RULE-12-2-3,Yes,Required,Decidable,Single Translation Unit,A named bit-field with signed integer type shall not have a length of one bit,"RULE-6-2, M9-6-4",,Import, +cpp,MISRA-C++-2023,RULE-12-2-2,Yes,Required,Decidable,Single Translation Unit,A bit-field shall have an appropriate type,RULE-6-1,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-12-2-3,Yes,Required,Decidable,Single Translation Unit,A named bit-field with signed integer type shall not have a length of one bit,M9-6-4,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-12-3-1,Yes,Required,Decidable,Single Translation Unit,The union keyword shall not be used,RULE-19-2,,Easy, cpp,MISRA-C++-2023,RULE-13-1-1,Yes,Advisory,Decidable,Single Translation Unit,Classes should not be inherited virtually,,,Easy, -cpp,MISRA-C++-2023,RULE-13-1-2,Yes,Required,Decidable,Single Translation Unit,An accessible base class shall not be both virtual and non-virtual in the same hierarchy,M10-1-3,,Import, +cpp,MISRA-C++-2023,RULE-13-1-2,Yes,Required,Decidable,Single Translation Unit,An accessible base class shall not be both virtual and non-virtual in the same hierarchy,M10-1-3,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-13-3-1,Yes,Required,Decidable,Single Translation Unit,"User-declared member functions shall use the virtual, override and final specifiers appropriately",,,Easy, -cpp,MISRA-C++-2023,RULE-13-3-2,Yes,Required,Decidable,Single Translation Unit,Parameters in an overriding virtual function shall not specify different default arguments,M8-3-1,,Import, -cpp,MISRA-C++-2023,RULE-13-3-3,Yes,Required,Decidable,System,The parameters in all declarations or overrides of a function shall either be unnamed or have identical names,A15-1-2,,Import, -cpp,MISRA-C++-2023,RULE-13-3-4,Yes,Required,Decidable,Single Translation Unit,A comparison of a potentially virtual pointer to member function shall only be with nullptr,A5-10-1,,Import, +cpp,MISRA-C++-2023,RULE-13-3-2,Yes,Required,Decidable,Single Translation Unit,Parameters in an overriding virtual function shall not specify different default arguments,M8-3-1,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-13-3-3,Yes,Required,Decidable,System,The parameters in all declarations or overrides of a function shall either be unnamed or have identical names,RULE-8-3,,Easy, +cpp,MISRA-C++-2023,RULE-13-3-4,Yes,Required,Decidable,Single Translation Unit,A comparison of a potentially virtual pointer to member function shall only be with nullptr,A5-10-1,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-14-1-1,Yes,Advisory,Decidable,Single Translation Unit,Non-static data members should be either all private or all public,,,Easy, cpp,MISRA-C++-2023,RULE-15-0-1,Yes,Required,Decidable,Single Translation Unit,Special member functions shall be provided appropriately,A12-0-1,,Medium, cpp,MISRA-C++-2023,RULE-15-0-2,Yes,Advisory,Decidable,Single Translation Unit,User-provided copy and move member functions of a class should have appropriate signatures,,,Easy, -cpp,MISRA-C++-2023,RULE-15-1-1,Yes,Required,Undecidable,System,An object’s dynamic type shall not be used from within its constructor or destructor,M12-1-1,,Import, -cpp,MISRA-C++-2023,RULE-15-1-2,Yes,Advisory,Decidable,Single Translation Unit,All constructors of a class should explicitly initialize all of its virtual base classes and immediate base classes,A12-1-1,,Import, +cpp,MISRA-C++-2023,RULE-15-1-1,Yes,Required,Undecidable,System,An object’s dynamic type shall not be used from within its constructor or destructor,M12-1-1,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-15-1-2,Yes,Advisory,Decidable,Single Translation Unit,All constructors of a class should explicitly initialize all of its virtual base classes and immediate base classes,A12-1-1,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-15-1-3,Yes,Required,Decidable,Single Translation Unit,Conversion operators and constructors that are callable with a single argument shall be explicit,"A12-1-4,A13-5-2",,Easy, cpp,MISRA-C++-2023,RULE-15-1-4,Yes,Advisory,Decidable,Single Translation Unit,"All direct, non-static data members of a class should be initialized before the class object is accessible",,,Hard, -cpp,MISRA-C++-2023,RULE-15-1-5,Yes,Required,Decidable,Single Translation Unit,A class shall only define an initializer-list constructor when it is the only constructor,A8-5-4,,Import, -cpp,MISRA-C++-2023,DIR-15-8-1,Yes,Required,Decidable,Implementation,User-provided copy assignment operators and move assignment operators shall handle self-assignment,A12-8-5,,Import, +cpp,MISRA-C++-2023,RULE-15-1-5,Yes,Required,Decidable,Single Translation Unit,A class shall only define an initializer-list constructor when it is the only constructor,A8-5-4,ImportMisra23,Import, +cpp,MISRA-C++-2023,DIR-15-8-1,Yes,Required,Decidable,Implementation,User-provided copy assignment operators and move assignment operators shall handle self-assignment,A12-8-5,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-16-5-1,Yes,Required,Decidable,Single Translation Unit,The logical AND and logical OR operators shall not be overloaded,M5-2-11,,Easy, -cpp,MISRA-C++-2023,RULE-16-5-2,Yes,Required,Decidable,Single Translation Unit,The address-of operator shall not be overloaded,M5-3-3,,Import, +cpp,MISRA-C++-2023,RULE-16-5-2,Yes,Required,Decidable,Single Translation Unit,The address-of operator shall not be overloaded,M5-3-3,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-16-6-1,Yes,Advisory,Decidable,Single Translation Unit,Symmetrical operators should only be implemented as non-member functions,,,Medium, -cpp,MISRA-C++-2023,RULE-17-8-1,Yes,Required,Decidable,Single Translation Unit,Function templates shall not be explicitly specialized,A14-8-2,,Import, -cpp,MISRA-C++-2023,RULE-18-1-1,Yes,Required,Decidable,Single Translation Unit,An exception object shall not have pointer type,A15-1-2,,Import, -cpp,MISRA-C++-2023,RULE-18-1-2,Yes,Required,Decidable,Single Translation Unit,An empty throw shall only occur within the compound-statement of a catch handler,M15-1-3,,Import, +cpp,MISRA-C++-2023,RULE-17-8-1,Yes,Required,Decidable,Single Translation Unit,Function templates shall not be explicitly specialized,A14-8-2,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-18-1-1,Yes,Required,Decidable,Single Translation Unit,An exception object shall not have pointer type,A15-1-2,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-18-1-2,Yes,Required,Decidable,Single Translation Unit,An empty throw shall only occur within the compound-statement of a catch handler,M15-1-3,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-18-3-1,Yes,Advisory,Decidable,Single Translation Unit,There should be at least one exception handler to catch all otherwise unhandled exceptions,A15-3-3,,Easy, cpp,MISRA-C++-2023,RULE-18-3-2,Yes,Required,Decidable,Single Translation Unit,An exception of class type shall be caught by const reference or reference,A15-3-5,,Easy, cpp,MISRA-C++-2023,RULE-18-3-3,Yes,Required,Decidable,Single Translation Unit,Handlers for a function-try-block of a constructor or destructor shall not refer to non-static members from their class or its bases,M15-3-3,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-18-4-1,Yes,Required,Decidable,Single Translation Unit,Exception-unfriendly functions shall be noexcept,A15-5-1,,Easy, -cpp,MISRA-C++-2023,RULE-18-5-1,Yes,Advisory,Undecidable,System,A noexcept function should not attempt to propagate an exception to the calling function,A15-4-2,,Import, +cpp,MISRA-C++-2023,RULE-18-5-1,Yes,Advisory,Undecidable,System,A noexcept function should not attempt to propagate an exception to the calling function,A15-4-2,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-18-5-2,Yes,Advisory,Decidable,Single Translation Unit,Program-terminating functions should not be used,,,Easy, cpp,MISRA-C++-2023,RULE-19-0-1,No,Required,Decidable,Single Translation Unit,A line whose first token is # shall be a valid preprocessing directive,,,, -cpp,MISRA-C++-2023,RULE-19-0-2,Yes,Required,Decidable,Single Translation Unit,Function-like macros shall not be defined,DIR-4-9,,Import, +cpp,MISRA-C++-2023,RULE-19-0-2,Yes,Required,Decidable,Single Translation Unit,Function-like macros shall not be defined,DIR-4-9,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-19-0-3,Yes,Advisory,Decidable,Single Translation Unit,#include directives should only be preceded by preprocessor directives or comments,RULE-20-1,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-19-0-4,Yes,Advisory,Decidable,Single Translation Unit,#undef should only be used for macros defined previously in the same file,,,Easy, cpp,MISRA-C++-2023,RULE-19-1-1,Yes,Required,Decidable,Single Translation Unit,The defined preprocessor operator shall be used appropriately,M16-1-1,,Easy, @@ -920,23 +920,23 @@ cpp,MISRA-C++-2023,RULE-19-2-1,Yes,Required,Decidable,Single Translation Unit,Pr cpp,MISRA-C++-2023,RULE-19-2-2,Yes,Required,Decidable,Single Translation Unit,"The #include directive shall be followed by either a or ""filename"" sequence",,,Easy, cpp,MISRA-C++-2023,RULE-19-2-3,Yes,Required,Decidable,Single Translation Unit,"The ' or "" or \ characters and the /* or // character sequences shall not occur in a header file name",A16-2-1,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-19-3-1,Yes,Advisory,Decidable,Single Translation Unit,The # and ## preprocessor operators should not be used,M16-3-2,ImportMisra23,Import, -cpp,MISRA-C++-2023,RULE-19-3-2,Yes,Required,Decidable,Single Translation Unit,A macro parameter immediately following a # operator shall not be immediately followed by a ## operator,RULE-20-11,,Import, -cpp,MISRA-C++-2023,RULE-19-3-3,Yes,Required,Decidable,Single Translation Unit,The argument to a mixed-use macro parameter shall not be subject to further expansion,RULE-20-12,,Import, +cpp,MISRA-C++-2023,RULE-19-3-2,Yes,Required,Decidable,Single Translation Unit,A macro parameter immediately following a # operator shall not be immediately followed by a ## operator,RULE-20-11,ImportMisra23,Import, +cpp,MISRA-C++-2023,RULE-19-3-3,Yes,Required,Decidable,Single Translation Unit,The argument to a mixed-use macro parameter shall not be subject to further expansion,RULE-20-12,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-19-3-4,Yes,Required,Decidable,Single Translation Unit,Parentheses shall be used to ensure macro arguments are expanded appropriately,M16-0-6,,Medium, cpp,MISRA-C++-2023,RULE-19-3-5,Yes,Required,Decidable,Single Translation Unit,Tokens that look like a preprocessing directive shall not occur within a macro argument,RULE-20-6,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-19-6-1,Yes,Advisory,Decidable,Single Translation Unit,The #pragma directive and the _Pragma operator should not be used,A16-7-1,,Easy, -cpp,MISRA-C++-2023,RULE-21-2-1,Yes,Required,Decidable,Single Translation Unit,"The library functions atof, atoi, atol and atoll from shall not be used",RULE-21-7,,Import, +cpp,MISRA-C++-2023,RULE-21-2-1,Yes,Required,Decidable,Single Translation Unit,"The library functions atof, atoi, atol and atoll from shall not be used",RULE-21-7,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-21-2-2,Yes,Required,Decidable,Single Translation Unit,"The string handling functions from , , and shall not be used",M18-0-5,,Easy, cpp,MISRA-C++-2023,RULE-21-2-3,Yes,Required,Decidable,Single Translation Unit,The library function system from shall not be used,M18-0-3,,Easy, -cpp,MISRA-C++-2023,RULE-21-2-4,Yes,Required,Decidable,Single Translation Unit,The macro offsetof shall not be used,M18-2-1,,Import, +cpp,MISRA-C++-2023,RULE-21-2-4,Yes,Required,Decidable,Single Translation Unit,The macro offsetof shall not be used,M18-2-1,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-21-6-1,Yes,Advisory,Undecidable,Single Translation Unit,Dynamic memory should not be used,DIR-4-12,,Easy, cpp,MISRA-C++-2023,RULE-21-6-2,Yes,Required,Decidable,Single Translation Unit,Dynamic memory shall be managed automatically,,,Easy, cpp,MISRA-C++-2023,RULE-21-6-3,Yes,Required,Decidable,Single Translation Unit,Advanced memory management shall not be used,,,Medium, -cpp,MISRA-C++-2023,RULE-21-6-4,Yes,Required,Decidable,System,"If a project defines either a sized or unsized version of a global operator delete, then both shall be defined",A18-5-4,,Import, +cpp,MISRA-C++-2023,RULE-21-6-4,Yes,Required,Decidable,System,"If a project defines either a sized or unsized version of a global operator delete, then both shall be defined",A18-5-4,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-21-6-5,Yes,Required,Decidable,Single Translation Unit,A pointer to an incomplete class type shall not be deleted,A5-3-3,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-21-10-1,Yes,Required,Decidable,Single Translation Unit,The features of shall not be used,DCL50-CPP,,Easy, cpp,MISRA-C++-2023,RULE-21-10-2,Yes,Required,Decidable,Single Translation Unit,The standard header file shall not be used,ERR52-CPP,,Easy, -cpp,MISRA-C++-2023,RULE-21-10-3,Yes,Required,Decidable,Single Translation Unit,The facilities provided by the standard header file shall not be used,M18-7-1,,Import, +cpp,MISRA-C++-2023,RULE-21-10-3,Yes,Required,Decidable,Single Translation Unit,The facilities provided by the standard header file shall not be used,M18-7-1,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-22-3-1,Yes,Required,Decidable,Single Translation Unit,The assert macro shall not be used with a constant-expression,,,Easy, cpp,MISRA-C++-2023,RULE-22-4-1,Yes,Required,Decidable,Single Translation Unit,The literal value zero shall be the only value assigned to errno,,,Easy, cpp,MISRA-C++-2023,RULE-23-11-1,Yes,Advisory,Decidable,Single Translation Unit,The raw pointer constructors of std::shared_ptr and std::unique_ptr should not be used,,,Easy, @@ -945,11 +945,11 @@ cpp,MISRA-C++-2023,RULE-24-5-2,Yes,Required,Decidable,Single Translation Unit,"T cpp,MISRA-C++-2023,RULE-25-5-1,Yes,Required,Decidable,Single Translation Unit,The setlocale and std::locale::global functions shall not be called,,,Easy, cpp,MISRA-C++-2023,RULE-25-5-2,Yes,Mandatory,Decidable,Single Translation Unit,"The pointers returned by the C++ Standard Library functions localeconv, getenv, setlocale or strerror must only be used as if they have pointer to const-qualified type",RULE-21-19,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-25-5-3,Yes,Mandatory,Undecidable,System,"The pointer returned by the C++ Standard Library functions asctime, ctime, gmtime, localtime, localeconv, getenv, setlocale or strerror must not be used following a subsequent call to the same function",RULE-21-20,ImportMisra23,Import, -cpp,MISRA-C++-2023,RULE-26-3-1,Yes,Advisory,Decidable,Single Translation Unit,std::vector should not be specialized with bool,A18-1-2,,Import, +cpp,MISRA-C++-2023,RULE-26-3-1,Yes,Advisory,Decidable,Single Translation Unit,std::vector should not be specialized with bool,A18-1-2,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-28-3-1,Yes,Required,Undecidable,System,Predicates shall not have persistent side effects,A25-1-1,,Easy, cpp,MISRA-C++-2023,RULE-28-6-1,Yes,Required,Decidable,Single Translation Unit,The argument to std::move shall be a non-const lvalue,A18-9-3,,Easy, -cpp,MISRA-C++-2023,RULE-28-6-2,Yes,Required,Decidable,Single Translation Unit,Forwarding references and std::forward shall be used together,A18-9-2,,Import, +cpp,MISRA-C++-2023,RULE-28-6-2,Yes,Required,Decidable,Single Translation Unit,Forwarding references and std::forward shall be used together,A18-9-2,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-28-6-3,Yes,Required,Decidable,Single Translation Unit,An object shall not be used while in a potentially moved-from state,A12-8-3,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-28-6-4,Yes,Required,Decidable,Single Translation Unit,"The result of std::remove, std::remove_if, std::unique and empty shall be used",,,Easy, -cpp,MISRA-C++-2023,RULE-30-0-1,Yes,Required,Decidable,Single Translation Unit,The C Library input/output functions shall not be used,M27-0-1,,Import, +cpp,MISRA-C++-2023,RULE-30-0-1,Yes,Required,Decidable,Single Translation Unit,The C Library input/output functions shall not be used,M27-0-1,ImportMisra23,Import, cpp,MISRA-C++-2023,RULE-30-0-2,Yes,Required,Undecidable,System,Reads and writes on the same file stream shall be separated by a positioning operation,A27-0-3,ImportMisra23,Import, diff --git a/scripts/generate_rules/generate_package_files.py b/scripts/generate_rules/generate_package_files.py index ed8bb625bd..862ccfdc1e 100644 --- a/scripts/generate_rules/generate_package_files.py +++ b/scripts/generate_rules/generate_package_files.py @@ -192,6 +192,9 @@ def write_shared_implementation(package_name, rule_id, query, language_name, ql_ if len(class_name) > 61: # Line break required after comma f.write("\n TestQuery\n{ }\n") + elif len(class_name) == 61: + # Line break required before `{` + f.write(" TestQuery\n{ }\n") elif len(class_name) > 57: # Line break required after `{` f.write(" TestQuery {\n}\n") diff --git a/scripts/generate_rules/templates/shared_library.ql.template b/scripts/generate_rules/templates/shared_library.ql.template index 24431edcc7..93dc503510 100644 --- a/scripts/generate_rules/templates/shared_library.ql.template +++ b/scripts/generate_rules/templates/shared_library.ql.template @@ -1,5 +1,10 @@ +{# + The autogenerated description of the shared query is copied from + the first matching query in `rule_packages`. +#} /** - * Provides a library which includes a `problems` predicate for reporting.... + * Provides a library with a `problems` predicate for the following issue: + * {{ description|join('\n * ') }} */ import cpp