Skip to content

Commit

Permalink
Merge pull request #827 from rak3-sh/rp/fix-540
Browse files Browse the repository at this point in the history
Fix #540: A3-9-1: Dont consider variables from template instantiations
  • Loading branch information
lcartey authored Dec 27, 2024
2 parents 89bd9b4 + 23ddafa commit db71d1b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions change_notes/2024-12-18-fix-fp-540-a3-9-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `A3-9-1` - `VariableWidthIntegerTypesUsed.ql`:
- Reduce false positives by not considering variables from template instantiations.
4 changes: 4 additions & 0 deletions cpp/autosar/src/rules/A3-9-1/VariableWidthIntegerTypesUsed.ql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ where
typeStrippedOfSpecifiers instanceof SignedCharType
) and
not v instanceof ExcludedVariable and
// Dont consider template instantiations because instantiations with
// Fixed Width Types are recorded after stripping their typedef'd type,
// thereby, causing false positives (#540).
not v.isFromTemplateInstantiation(_) 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
Expand Down
13 changes: 12 additions & 1 deletion cpp/autosar/test/rules/A3-9-1/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,15 @@ void test_variable_width_type_qualified_variables() {
struct test_fix_fp_614 {
test_fix_fp_614 operator++(int); // COMPLIANT
test_fix_fp_614 operator--(int); // COMPLIANT
};
};

// COMPLIANT - instantiated with Fixed Width Types.
template <typename MyType> constexpr void test_fix_fp_540(MyType value) {
value++;
}

int call_test_fix_fp_540() {
test_fix_fp_540<std::uint8_t>(19);
test_fix_fp_540<std::int16_t>(20);
return 0;
}

0 comments on commit db71d1b

Please sign in to comment.