diff --git a/change_notes/2024-06-18-fix-fp-614-A3-9-1.md b/change_notes/2024-06-18-fix-fp-614-A3-9-1.md new file mode 100644 index 0000000000..121c285b20 --- /dev/null +++ b/change_notes/2024-06-18-fix-fp-614-A3-9-1.md @@ -0,0 +1,2 @@ +- `A3-9-1` - `VariableWidthIntegerTypesUsed.ql`: + - Fixes #614. Excludes post increment and decrement operators. \ No newline at end of file diff --git a/cpp/autosar/src/rules/A3-9-1/VariableWidthIntegerTypesUsed.ql b/cpp/autosar/src/rules/A3-9-1/VariableWidthIntegerTypesUsed.ql index 460457e0f8..84a38b0f6a 100644 --- a/cpp/autosar/src/rules/A3-9-1/VariableWidthIntegerTypesUsed.ql +++ b/cpp/autosar/src/rules/A3-9-1/VariableWidthIntegerTypesUsed.ql @@ -20,6 +20,7 @@ import codingstandards.cpp.autosar import codingstandards.cpp.EncapsulatingFunctions import codingstandards.cpp.BuiltInNumericTypes import codingstandards.cpp.Type +import codingstandards.cpp.Operator from Variable v, Type typeStrippedOfSpecifiers where @@ -30,5 +31,8 @@ where typeStrippedOfSpecifiers instanceof UnsignedCharType or typeStrippedOfSpecifiers instanceof SignedCharType ) and - not v instanceof ExcludedVariable + not v instanceof ExcludedVariable and + //post-increment/post-decrement operators are required by the standard to have a dummy int parameter + not v.(Parameter).getFunction() instanceof PostIncrementOperator and + not v.(Parameter).getFunction() instanceof PostDecrementOperator select v, "Variable '" + v.getName() + "' has variable-width type." diff --git a/cpp/autosar/test/rules/A3-9-1/test.cpp b/cpp/autosar/test/rules/A3-9-1/test.cpp index 9d1e257b8c..882738eea1 100644 --- a/cpp/autosar/test/rules/A3-9-1/test.cpp +++ b/cpp/autosar/test/rules/A3-9-1/test.cpp @@ -70,4 +70,9 @@ void test_variable_width_type_qualified_variables() { volatile long l2; // NON_COMPLIANT volatile unsigned long ul2; // NON_COMPLIANT volatile signed long sl2; // NON_COMPLIANT -} \ No newline at end of file +} + +struct test_fix_fp_614 { + test_fix_fp_614 operator++(int); // COMPLIANT + test_fix_fp_614 operator--(int); // COMPLIANT +}; \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/Operator.qll b/cpp/common/src/codingstandards/cpp/Operator.qll index 9f4c5558eb..6d2cc39933 100644 --- a/cpp/common/src/codingstandards/cpp/Operator.qll +++ b/cpp/common/src/codingstandards/cpp/Operator.qll @@ -215,6 +215,20 @@ class IncrementOperator extends Operator { } } +class PostIncrementOperator extends Operator { + PostIncrementOperator() { + hasName("operator++") and + getNumberOfParameters() = 1 + } +} + +class PostDecrementOperator extends Operator { + PostDecrementOperator() { + hasName("operator--") and + getNumberOfParameters() = 1 + } +} + class StructureDerefOperator extends Operator { StructureDerefOperator() { hasName("operator->") and