<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - clang emits extraneous -Wunused-variable for RAII const reference variable"
href="https://bugs.llvm.org/show_bug.cgi?id=36627">36627</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang emits extraneous -Wunused-variable for RAII const reference variable
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>5.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>anntzer.lee@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Consider
struct S {
S();
~S(); // Assume this actually does some RAII cleanup.
};
extern int f();
int main() {
auto const t = S(); // No warning.
auto const& u = S(); // "warning: unused variable 'u'
[-Wunused-variable]".
f(); // Just so that clang has no way to know whether some work will
be done here.
}
and compile (e.g.) with `--std=c++17 -Wall -Wextra -Wpedantic`
clang (5.0.1 Arch Linux package) correctly recognizes that `t` could be
involved in RAII, but emits an unused-variable warning about `u` even though it
can also participate in RAII in the same way (as the lifetime of the const
reference is prolonged until the end of the scope). [Note that it would be a
different issue if clang neither recognized the possibility of RAII happening
for either `t` or `u`.]</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>