The checker should ignore requirement expressions inside concept
definitions, because redundant expressions still make sense here
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks for the fix, can you also add a release note for it?
I'm a bit worried about using hasAncestor() for this; that has a tendency to do surprising things in addition to being expensive because it's very greedy. However, I can't see a situation in which it's going to be wrong, because the body of the requires expression is always unevaluated (so we really don't need to worry about nonsense like defining a lambda in the requires body, and then defining a class in the lambda, and having a redundant expression we care to diagnose in a member function of that class).
@alexfh or @sammccall -- do you see any concerns with this use of hasAncestor()?
I don't actually know a great deal about matcher performance :-( I wish I did.
I think this is pretty much in line with how plenty of check matchers already work though, in particular unless(isInTemplateInstantiation()) is basically the same thing and is used in many places including this check.
So I wouldn't be particularly worried.
(Obviously from first principles you'd prefer to prune the subtree rather than match within it and then walk up the parent chain, but I don't think matchers supports this pattern well).
Okie dokie, thanks for weighing in! This LGTM (feel free to add the release note when landing). If @alexfh has some technical concerns with hasAncestor(), we can always revert and address them once we know more.
I feel like this is another issue which could be solved with traversal scopes. isInEvaluationContext This traversal scope wouldn't traverse things like concepts, static_asserts(?), Noexcept & explicit specifiers, sizeof, decltype etc.
Just address that test issue then it'll be good
clang-tools-extra/test/clang-tidy/checkers/misc/redundant-expression.cpp | ||
---|---|---|
1 | This is removing test coverage for previous language versions unnecessarily. Can you create a new test file redundant-expression-cxx20 instead and move this new test case into there. |
The new file was failing with message
CHECK-FIXES, CHECK-MESSAGES or CHECK-NOTES not found in the input
So I had to add an additional urrelevant check.
I added a check for consteval function (there were no such tests previously).
You don't need the unrelated tests, you can use a special run line that will check that no warnings are emitted.
// RUN: clang-tidy %s --checks=-*,misc-redundant-expression -- | count 0
LGTM, just one small nit.
clang-tools-extra/test/clang-tidy/checkers/misc/redundant-expression-cxx20.cpp | ||
---|---|---|
3 ↗ | (On Diff #461003) | This comment isn't strictly necessary |
This is removing test coverage for previous language versions unnecessarily. Can you create a new test file redundant-expression-cxx20 instead and move this new test case into there.