Skip to content

Commit

Permalink
Merge pull request #636 from knewbury01/knewbury01/fix-621
Browse files Browse the repository at this point in the history
A7-1-1: improve template handling
  • Loading branch information
knewbury01 authored Jul 5, 2024
2 parents 1fd5675 + 652356b commit 3fb6ac2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions change_notes/2024-07-05-fix-fp-621-A7-1-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `A7-1-1` - `DeclarationUnmodifiedObjectMissingConstSpecifier.ql`:
- Fixes #621. Exclude template instantiations that come from constexpr templates.
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ where
) and
not exists(LambdaExpression lc | lc.getACapture().getField() = v) and
not v.isFromUninstantiatedTemplate(_) and
not v.isCompilerGenerated()
not v.isCompilerGenerated() 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."
9 changes: 8 additions & 1 deletion cpp/autosar/test/rules/A7-1-1/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@ int main(int, char **) noexcept {
new A7_1_1b<A7_1_1bHelper>(0);

(new Issue18)->F(0);
}
}

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>; }

0 comments on commit 3fb6ac2

Please sign in to comment.