}
const CXXMethodDecl* OldMethod = dyn_cast<CXXMethodDecl>(Old);
- const CXXMethodDecl* NewMethod = dyn_cast<CXXMethodDecl>(New);
+ CXXMethodDecl* NewMethod = dyn_cast<CXXMethodDecl>(New);
if (OldMethod && NewMethod) {
- if (!NewMethod->getFriendObjectKind() &&
- NewMethod->getLexicalDeclContext()->isRecord()) {
+ // Preserve triviality.
+ NewMethod->setTrivial(OldMethod->isTrivial());
+
+ bool isFriend = NewMethod->getFriendObjectKind();
+
+ if (!isFriend && NewMethod->getLexicalDeclContext()->isRecord()) {
// -- Member function declarations with the same name and the
// same parameter types cannot be overloaded if any of them
// is a static member function declaration.
Diag(New->getLocation(), NewDiag);
Diag(Old->getLocation(), PrevDiag) << Old << Old->getType();
- } else {
- if (OldMethod->isImplicit()) {
+
+ // Complain if this is an explicit declaration of a special
+ // member that was initially declared implicitly.
+ //
+ // As an exception, it's okay to befriend such methods in order
+ // to permit the implicit constructor/destructor/operator calls.
+ } else if (OldMethod->isImplicit()) {
+ if (isFriend) {
+ NewMethod->setImplicit();
+ } else {
Diag(NewMethod->getLocation(),
diag::err_definition_of_implicitly_declared_member)
- << New << getSpecialMember(Context, OldMethod);
-
- Diag(OldMethod->getLocation(),
- diag::note_previous_implicit_declaration);
+ << New << getSpecialMember(Context, OldMethod);
return true;
}
}
}
}
- // Notify the class that we've added a constructor.
- ClassDecl->addedConstructor(Context, Constructor);
+ // Notify the class that we've added a constructor. In principle we
+ // don't need to do this for out-of-line declarations; in practice
+ // we only instantiate the most recent declaration of a method, so
+ // we have to call this for everything but friends.
+ if (!Constructor->getFriendObjectKind())
+ ClassDecl->addedConstructor(Context, Constructor);
}
/// CheckDestructor - Checks a fully-formed destructor for well-formedness,
// RUN: %clang_cc1 -fsyntax-only -verify %s
-struct A { }; // expected-note {{previous implicit declaration is here}}
+struct A { };
A::A() { } // expected-error {{definition of implicitly declared constructor}}
-struct B { }; // expected-note {{previous implicit declaration is here}}
+struct B { };
B::B(const B&) { } // expected-error {{definition of implicitly declared copy constructor}}
-struct C { }; // expected-note {{previous implicit declaration is here}}
+struct C { };
C& C::operator=(const C&) { return *this; } // expected-error {{definition of implicitly declared copy assignment operator}}
-struct D { }; // expected-note {{previous implicit declaration is here}}
+struct D { };
D::~D() { } // expected-error {{definition of implicitly declared destructor}}
// Make sure that the special member functions are introduced for