[llvm-bugs] [Bug 25901] New: "cannot define the implicit copy assignment operator" error could be more useful
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Dec 20 02:29:48 PST 2015
https://llvm.org/bugs/show_bug.cgi?id=25901
Bug ID: 25901
Summary: "cannot define the implicit copy assignment operator"
error could be more useful
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: hfinkel at anl.gov
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
Classification: Unclassified
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).
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151220/cd4ad4f0/attachment.html>
More information about the llvm-bugs
mailing list