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

Exclude rvalue references from const in AUTOSAR rule 7-1-1. #814

Open
wants to merge 5 commits 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-10-udpate-a7-1-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `A7-1-1` - `DeclarationUnmodifiedObjectMissingConstSpecifier.ql`:
- Exclude rvalue references.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ where
not exists(LambdaExpression lc | lc.getACapture().getField() = v) and
not v.isFromUninstantiatedTemplate(_) and
not v.isCompilerGenerated() and
not v.getType() instanceof RValueReferenceType and
//if the instantiation is not constexpr but the template is, still exclude it as a candidate
not exists(TemplateVariable b | b.getAnInstantiation() = v and b.isConstexpr())
select v, "Non-constant variable " + v.getName() + cond + " and is not modified."
14 changes: 13 additions & 1 deletion cpp/autosar/test/rules/A7-1-1/test.cpp
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified the test failed without the change in the previous commit due to

+| test.cpp:93:47:93:50 | rest | Non-constant variable rest points to an object and is not modified. |

Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,16 @@ template <bool... Args> extern constexpr bool recurse_var = true; // COMPLIANT
template <bool B1, bool... Args>
extern constexpr bool recurse_var<B1, Args...> = B1 &&recurse_var<Args...>;

void fp_621() { recurse_var<true, true, true>; }
void fp_621() { recurse_var<true, true, true>; }

#include <utility>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added all at the end of the file to minimize updates to the expected files due to line numbers. But not sure if due to (auto) formatting rules or else it would be preferable otherwise.


void variadic_forwarding() {}

template <typename T, typename... Args>
void variadic_forwarding(T &&first, Args &&... rest) {
first;
variadic_forwarding(std::forward<Args>(rest)...);
}

int test_variadic_forwarding() { variadic_forwarding(1, 1.1, "a"); }