[PATCH] D152495: [Clang][SemaCXX] Add unused warning for variables declared in condition expressions

Corentin Jabot via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 13 06:44:40 PDT 2023


cor3ntin added inline comments.


================
Comment at: clang/lib/Sema/SemaExprCXX.cpp:4016-4019
+  // Ensure that `-Wunused-variable` will be emitted for condition variables
+  // that are not referenced later. e.g.: if (int var = init());
+  if (!T->isAggregateType())
+    ConditionVar->setReferenced(/*R=*/false);
----------------
aaron.ballman wrote:
> `isAggregateType()` includes arrays and I think we still want to diagnose an unused array.
Should it not be `Condition->hasSideEffects()` ? 
Hopefully we want to be consistent with existing behavior https://godbolt.org/z/6abbPhn4G


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152495/new/

https://reviews.llvm.org/D152495



More information about the cfe-commits mailing list