[clang] [Clang] emit -Wunused-variable warning for unused structured bindings without the [[maybe_unused]] attribute (PR #127061)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 11 09:19:43 PDT 2025


================
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2c -Wunused %s
+
+namespace GH125810 {
+struct S {
+  int a, b;
+};
+
+void t(S s) {
+  auto &[_, _] = s;
+  auto &[a1, _] = s; // expected-warning {{unused variable '[a1, _]'}}
----------------
AaronBallman wrote:

> the entire binding declaration is used as the diagnostic location, including all binding elements, even when only some of them are actually unused. Is this the expected behavior?

It's the current behavior but I think we could improve it. For example, it would be much better in this case to point to each binding declaration that's unused as opposed to the whole structured binding. But the behavior for now is okay.

https://github.com/llvm/llvm-project/pull/127061


More information about the cfe-commits mailing list