-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Open
Labels
bugzillaIssues migrated from bugzillaIssues migrated from bugzillac++17clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-positiveWarning fires when it should notWarning fires when it should not
Description
| Bugzilla Link | 35450 |
| Version | trunk |
| OS | Linux |
| Reporter | LLVM Bugzilla Contributor |
| CC | @AaronBallman,@zmodem,@JVApen,@Meinersbur |
Extended Description
The warning -Wunused-lambda-capture may indicate that a capture is unused if the body of the lambda contains an if constexpr construct and the capture is only used in the branch which was not instantiated.
Although Clang is technically correct that the capture is not used, the warning is unhelpful, since the capture cannot simply be removed without breaking cases that instantiate the the other branch.
If this is hard to fix "correctly", then Clang should suppress this warning for lambdas that contain an if-constexpr block.
Example:
template <bool b>
int foo(int a) {
auto f = [&a]() {
if constexpr(b) {
return a;
} else {
return 0;
}
};
return f();
}
void bar() {
foo<false>(123); // generates unused-capture warning in instantiation
foo<true>(123); // no warning
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugzillaIssues migrated from bugzillaIssues migrated from bugzillac++17clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-positiveWarning fires when it should notWarning fires when it should not