-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
Spurious -Wunused-lambda-capture in presence of "if constexpr" #34798
Comments
Sorry, this does not seem to be getting fixed for clang 10, and I don't think we can block on it. |
Is there any update on when this can get fixed? |
Also causes problems when compiling flang: https://reviews.llvm.org/rGd4a1db4f3fd7 |
I can confirm that this behavior still appears on trunk. When instantiating the template for llvm-project/clang/lib/Sema/TreeTransform.h Line 7392 in ac7c880
llvm-project/clang/lib/Sema/TreeTransform.h Line 7402 in ac7c880
Because we only transform one branch per instantiation, we don't ever mark the capture as being used. However, this is done according to the standard: https://eel.is/c++draft/stmt.if#2.sentence-3 Because we can't instantiate the branch-not-taken when it's no longer dependent, I think we have to decide whether we'd rather have false positives or false negatives. Given that a false positive is trivial to workaround (add |
With trunk: |
Confirmed still an issue in v18.1 |
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:
The text was updated successfully, but these errors were encountered: