[cfe-commits] r103127 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/SemaCXX/default-assignment-operator.cpp
Douglas Gregor
dgregor at apple.com
Wed May 5 15:38:16 PDT 2010
Author: dgregor
Date: Wed May 5 17:38:15 2010
New Revision: 103127
URL: http://llvm.org/viewvc/llvm-project?rev=103127&view=rev
Log:
When implicit definition of the copy-assignment operator fails,
provide a note that shows where the copy-assignment operator was
needed. We used to have this, but I broke it during refactoring.
Finishes PR6999.
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/default-assignment-operator.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=103127&r1=103126&r2=103127&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed May 5 17:38:15 2010
@@ -4471,8 +4471,10 @@
move(To), Owned(From),
/*CopyingBaseSubobject=*/true);
if (Copy.isInvalid()) {
- Invalid = true;
- continue;
+ Diag(CurrentLocation, diag::note_member_synthesized_at)
+ << CXXCopyAssignment << Context.getTagDeclType(ClassDecl);
+ CopyAssignOperator->setInvalidDecl();
+ return;
}
// Success! Record the copy.
@@ -4491,7 +4493,8 @@
Diag(ClassDecl->getLocation(), diag::err_uninitialized_member_for_assign)
<< Context.getTagDeclType(ClassDecl) << 0 << Field->getDeclName();
Diag(Field->getLocation(), diag::note_declared_at);
- Diag(Loc, diag::note_first_required_here);
+ Diag(CurrentLocation, diag::note_member_synthesized_at)
+ << CXXCopyAssignment << Context.getTagDeclType(ClassDecl);
Invalid = true;
continue;
}
@@ -4502,7 +4505,8 @@
Diag(ClassDecl->getLocation(), diag::err_uninitialized_member_for_assign)
<< Context.getTagDeclType(ClassDecl) << 1 << Field->getDeclName();
Diag(Field->getLocation(), diag::note_declared_at);
- Diag(Loc, diag::note_first_required_here);
+ Diag(CurrentLocation, diag::note_member_synthesized_at)
+ << CXXCopyAssignment << Context.getTagDeclType(ClassDecl);
Invalid = true;
continue;
}
@@ -4592,8 +4596,10 @@
move(To), move(From),
/*CopyingBaseSubobject=*/false);
if (Copy.isInvalid()) {
- Invalid = true;
- continue;
+ Diag(CurrentLocation, diag::note_member_synthesized_at)
+ << CXXCopyAssignment << Context.getTagDeclType(ClassDecl);
+ CopyAssignOperator->setInvalidDecl();
+ return;
}
// Success! Record the copy.
Modified: cfe/trunk/test/SemaCXX/default-assignment-operator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/default-assignment-operator.cpp?rev=103127&r1=103126&r2=103127&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/default-assignment-operator.cpp (original)
+++ cfe/trunk/test/SemaCXX/default-assignment-operator.cpp Wed May 5 17:38:15 2010
@@ -1,15 +1,14 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
class Base { // expected-error {{cannot define the implicit default assignment operator for 'Base', because non-static reference member 'ref' can't use default assignment operator}} \
- // expected-warning{{class 'Base' does not declare any constructor to initialize its non-modifiable members}} \
- // expected-note {{synthesized method is first required here}}
+ // expected-warning{{class 'Base' does not declare any constructor to initialize its non-modifiable members}}
int &ref; // expected-note {{declared here}} \
// expected-note{{reference member 'ref' will never be initialized}}
};
class X : Base { // // expected-error {{cannot define the implicit default assignment operator for 'X', because non-static const member 'cint' can't use default assignment operator}} \
- // expected-note {{synthesized method is first required here}}
-public:
+// expected-note{{assignment operator for 'Base' first required here}}
+public:
X();
const int cint; // expected-note {{declared here}}
};
@@ -29,7 +28,7 @@
// Test1
void f(X x, const X cx) {
- x = cx;
+ x = cx; // expected-note{{assignment operator for 'X' first required here}}
x = cx;
z1 = z2;
}
@@ -74,8 +73,7 @@
// Test5
-class E1 { // expected-error{{cannot define the implicit default assignment operator for 'E1', because non-static const member 'a' can't use default assignment operator}} \
- // expected-note {{synthesized method is first required here}}
+class E1 { // expected-error{{cannot define the implicit default assignment operator for 'E1', because non-static const member 'a' can't use default assignment operator}}
public:
const int a; // expected-note{{declared here}}
@@ -86,7 +84,7 @@
E1 e1, e2;
void j() {
- e1 = e2;
+ e1 = e2; // expected-note{{assignment operator for 'E1' first required here}}
}
namespace ProtectedCheck {
More information about the cfe-commits
mailing list