Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #540: A3-9-1: Dont consider variables from template instantiations #827

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}