[PATCH] D152495: [Clang][SemaCXX] Add unused warning for variables declared in condition expressions
Takuya Shimizu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 31 17:22:33 PDT 2023
hazohelet added a comment.
Thank you for the feedback and the revert!
Distinguishing condition variables from other unused variables in Wunused warnings was something I was trying initially, and I agree that it's the best way forward.
The difficulty is in how to know whether an unused `VarDecl` is a condition variable or not in the phase of emitting `Wunused-variable`. We may need to add a boolean flag `IsConditionVar` in `VarDecl` or something.
The reason `[[maybe_unused]]` works well is that it is explicitly handled in `Sema::ShouldDiagnoseUnusedDecl` (https://github.com/llvm/llvm-project/blob/e7bd43675753476e97e63aa13c13b3498407ed1c/clang/lib/Sema/SemaDecl.cpp#L2005-L2007)
The `used` attribute regression was caused by the "used but not-referenced variables should be diagnosed as unused" change. Once we have some way of knowing that a `VarDecl` is a condition variable, we should only apply this change to condition variables, thereby avoiding regression.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152495/new/
https://reviews.llvm.org/D152495
More information about the cfe-commits
mailing list