<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54489>54489</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
-Wunused-variable triggers for temporaries with side effects when bound to a reference
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:diagnostics
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
cor3ntin
</td>
</tr>
</table>
<pre>
The following code warns on `guard2` and `guard3` (but not guard) despite all 3 variable having side effects on destruction.
This feels inconsistent and surprising.
GCC emits no warning in any of these cases.
```cpp
struct RAIIWrapper {
RAIIWrapper();
~RAIIWrapper();
};
void foo() {
auto const guard = RAIIWrapper();
auto const& guard2 = RAIIWrapper(); //unused variable 'guard2'
auto && guard3 = RAIIWrapper(); //unused variable 'guard3'
}
```
https://godbolt.org/z/zr7dsevoc
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydU0tvozAQ_jXmMmpETALhwKFtdle9rir1bOwJeOV4kG0SdX_9DpBN0krVSouMsefxffOiJfPevPYIB3KOztZ3oMkgnFXwEciDKPNuVMFIPoDy5iooJoGQu3ZM4CnBLBSyBoNxsAlBOQcFnFSwqnUIvTpN6NEyOh4OqNOMz9YpjDpZ8iuR70X--NrbCAdEF8F6TT7amNCnmTyOYQg2MtDF-MfzM-DRMpanOeiJw3o2fgc6QOoxImgVMV4cLnuZL0sPw718iQV-Pr68vAU1DBhAVE-LDvi5U3DqnK0o7rSi-va1gaj2t_O8n8garjsthh-J1JgIpuQTLJUFUez_QX_zEbJcvOSXbty677xGP0Y0ty4JWV3aLatPyAx6xS3-F7e44k71-NiL-9r0KQ1RFI8LWkemJZdWFDq-_Z7eUJmIJ9KZaQpTF7XKkk0Om4e3hfrhSp2C7ToMPFMUIOFxoMAqjHC2qf84j-cePbQ08qRxwgoCHjCg15iNwTWfYmLvsV1pOvLFudPfz8MQ6Bej8dXGOGLkw3az2dVZ31RYbqQuN6aVdanQVCzeKZTrel22W7nNnGp57huxfRJSaqd8x3zGqs5TTFYzlhTbfWYbmUuZF3ItZVGt5areyqo0udqVNWq1QbHJ8aisW00RTWXLQjMH145dZKXjfyrelCpG23nEmZjxud89hUZTKHyyPpsTaeYs_gAYikrF">