<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - Incorrect error message when trying to modify a const reference in lambda" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24016&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=Z5fj5Jrt5NKlp3rekd8yuG4t6G476o9bB3a70slOUX8&s=XP4ikqZt9GENAvskEYDmcdHb8Q9oe0DbymCQc-OvoDk&e=">24016</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Incorrect error message when trying to modify a const reference in lambda
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.6
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>fynjycfdby@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>This code:
int main() {
int x = 0;
const int& rx = x;
auto l = [&rx]() {
rx = 5;
};
}
produces error message:
test.cpp:5:12: error: cannot assign to a variable captured by copy in a
non-mutable lambda
rx = 5;
~~ ^
Moreover, even this code:
int main() {
int x = 0;
const int& rx = x;
auto l = [&rx]() mutable {
rx = 5;
};
}
produces the same error message.
But the message should rather say that modifying const reference is not
allowed.</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>