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: unassignedclangb...@nondot.org Reporter: hfin...@anl.gov CC: dgre...@apple.com, llvm-bugs@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.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs