<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/125810>125810</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] `-Wunused-variable` false negative when not all structured bindings are marked `maybe_unused`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zwuis
</td>
</tr>
</table>
<pre>
Clang doesn't emit warning when all structured bindings are unused but not all structured bindings are marked `maybe_unused`.
```cpp
struct S {
int a, b;
};
void test(S s) {
auto &[a1, _] = s; // "unused variable" warning emitted expectedly
auto &[a2, b2 [[maybe_unused]]] = s; // no warning emitted unexpectedly
auto &[_, b3 [[maybe_unused]]] = s; // no warning emitted expectedly
}
```
Compiler Explorer: <https://godbolt.org/z/vnf9Ma3nb>
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykU02PozoQ_DXNpZXItIMJBw75mNzeaQ7vODKhQ_yesZFtMh-_fgVkZ3d2VrvSrtQSyHRXdRUuHaPpHHMNxR6KY6bHdPWhfnseTcwa377WB6tdh63n6IDKhNybhM86OOM6fL6yQ20txhTGcxoDt9gY1xrXRdSBcXRjnM7GhM6nX7b2OvzPLYISvX5t-GkZBSXWIHZTKbHUeRhA7BYYfEQo99PXA8FOoHEJNdABG5DzcXm8v4jdzZsWE8cEtH3ECFR9nNVj8gikoNjrfMJ4guKIII8YQe4R6AR0QiC6i7rpYHRjGYjeDZncSdwivwx8Ttza15_j07wj4Wz7_oPg4rjUJ2bnP9GM7jdETzOP_Fuejyzl8fvfsZh78P1gLAd8eBmsDxxA7hDk4ZrSEEHuFuzOt423ae1DB3R6Azrd3KX6R0vXgHzI2lq2lax0xnVeym0pK6Hy7Frn5TZXKpeFlueG-EyVpk0rVMWVUrrIM1OToEKQKEQpNpSvZZ5X5aXQF11sleISNoJ7beza2ls_0WcmxpHrnIptLjKrG7bxawhCPXWtmrGLsBHWxBS_zSWT7ByXORizf0qs_l1MXb3fCSXwom1kdNzpZG68ZOWPQ5CNwdY_mGnSdWzWZ98Dnab97o_VEPx_fE5Ap1lkBDrddd5q-hIAAP__bAM4Qg">