<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 --- - "cannot define the implicit copy assignment operator" error could be more useful"
href="https://llvm.org/bugs/show_bug.cgi?id=25901">25901</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>"cannot define the implicit copy assignment operator" error could be more useful
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</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>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>hfinkel@anl.gov
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Consider the following:
$ cat /tmp/ao.cpp
struct Foo;
struct Bar {
Foo &R;
Bar(Foo &R) : R(R) {}
};
void test(Bar &B, Foo &F) {
B = Bar(F);
}
We currently produce this:
$ clang++ -fsyntax-only /tmp/ao.cpp
/tmp/ao.cpp:2:8: error: cannot define the implicit copy assignment operator for
'Bar', because non-static reference member 'R' cannot use copy assignment
operator
struct Bar {
^
/tmp/ao.cpp:3:8: note: declared here
Foo &R;
^
/tmp/ao.cpp:9:5: note: implicit copy assignment operator for 'Bar' first
required here
B = Bar(F);
^
1 error generated.
g++ (4.8.2) produces this:
$ g++ -fsyntax-only /tmp/ao.cpp
/tmp/ao.cpp: In member function ‘Bar& Bar::operator=(const Bar&)’:
/tmp/ao.cpp:2:8: error: non-static reference member ‘Foo& Bar::R’, can’t use
default assignment operator
struct Bar {
^
/tmp/ao.cpp: In function ‘void test(Bar&, Foo&)’:
/tmp/ao.cpp:9:5: note: synthesized method ‘Bar& Bar::operator=(const Bar&)’
first required here
B = Bar(F);
^
In this case I find g++'s error more useful, primarily because it tells me
exactly what method cannot be implicitly defined ('Bar& Bar::operator=(const
Bar&)' in this case). This information is directly useful to the user (the user
can define exactly that operator method as he or she sees fit in order to solve
the problem). I suggest we do the same (provide the signature of the missing
method).
Second, it might also be useful to:
1. Explain the source of the problem (it is not possible to rebind a
reference).
2. Suggest that the user might want to change the reference member to a
pointer member (in my experience, this is the most common solution).</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>