Implement deletion of explicitly defaulted default constructors.
We still don't parse out-of-line defaults correctly, which is needed to get the full effect out of this patch. llvm-svn: 131223
This commit is contained in:
parent
610128eba6
commit
b315302bf9
|
@ -3632,6 +3632,10 @@ def err_defaulted_default_ctor_params : Error<
|
||||||
"an explicitly-defaulted default constructor must have no parameters">;
|
"an explicitly-defaulted default constructor must have no parameters">;
|
||||||
def err_incorrect_defaulted_exception_spec : Error<
|
def err_incorrect_defaulted_exception_spec : Error<
|
||||||
"exception specification of explicitly defaulted function is incorrect">;
|
"exception specification of explicitly defaulted function is incorrect">;
|
||||||
|
def err_out_of_line_default_deletes : Error<
|
||||||
|
"defaulting this %select{default constructor|copy constructor|copy "
|
||||||
|
"assignment operator|destructor}0 would delete it after its first "
|
||||||
|
"declaration">;
|
||||||
|
|
||||||
def warn_array_index_precedes_bounds : Warning<
|
def warn_array_index_precedes_bounds : Warning<
|
||||||
"array index of '%0' indexes before the beginning of the array">,
|
"array index of '%0' indexes before the beginning of the array">,
|
||||||
|
|
|
@ -1518,7 +1518,6 @@ Sema::CXXSpecialMember Sema::getSpecialMember(const CXXMethodDecl *MD) {
|
||||||
if (MD->isCopyAssignmentOperator())
|
if (MD->isCopyAssignmentOperator())
|
||||||
return Sema::CXXCopyAssignment;
|
return Sema::CXXCopyAssignment;
|
||||||
|
|
||||||
llvm_unreachable("getSpecialMember on non-special member");
|
|
||||||
return Sema::CXXInvalid;
|
return Sema::CXXInvalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4220,9 +4219,6 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
|
||||||
|
|
||||||
isVirtualOkay = !isStatic;
|
isVirtualOkay = !isStatic;
|
||||||
} else {
|
} else {
|
||||||
if (DefaultLoc.isValid())
|
|
||||||
Diag(DefaultLoc, diag::err_default_special_members);
|
|
||||||
|
|
||||||
// Determine whether the function was written with a
|
// Determine whether the function was written with a
|
||||||
// prototype. This true when:
|
// prototype. This true when:
|
||||||
// - we're in C++ (where every function has a prototype),
|
// - we're in C++ (where every function has a prototype),
|
||||||
|
@ -4778,33 +4774,13 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check explicitly defaulted methods
|
if (DefaultLoc.isValid()) {
|
||||||
// FIXME: This could be made better through CXXSpecialMember if it did
|
CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewFD);
|
||||||
// default constructors (which it should rather than any constructor).
|
if (MD && getSpecialMember(MD) != CXXInvalid) {
|
||||||
if (NewFD && DefaultLoc.isValid() && getLangOptions().CPlusPlus) {
|
MD->setExplicitlyDefaulted();
|
||||||
if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewFD)) {
|
MD->setDefaulted();
|
||||||
if (CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(MD)) {
|
} else {
|
||||||
if (CD->isDefaultConstructor() || CD->isCopyOrMoveConstructor()) {
|
Diag(DefaultLoc, diag::err_default_special_members);
|
||||||
CD->setDefaulted();
|
|
||||||
CD->setExplicitlyDefaulted();
|
|
||||||
if (CD != CD->getCanonicalDecl() && CD->isDefaultConstructor())
|
|
||||||
CheckExplicitlyDefaultedDefaultConstructor(CD);
|
|
||||||
// FIXME: Do copy/move ctors here.
|
|
||||||
} else {
|
|
||||||
Diag(DefaultLoc, diag::err_default_special_members);
|
|
||||||
}
|
|
||||||
} else if (CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) {
|
|
||||||
DD->setDefaulted();
|
|
||||||
DD->setExplicitlyDefaulted();
|
|
||||||
// FIXME: Add a checking method
|
|
||||||
} else if (MD->isCopyAssignmentOperator() /* ||
|
|
||||||
MD->isMoveAssignmentOperator() */) {
|
|
||||||
MD->setDefaulted();
|
|
||||||
MD->setExplicitlyDefaulted();
|
|
||||||
// FIXME: Add a checking method
|
|
||||||
} else {
|
|
||||||
Diag(DefaultLoc, diag::err_default_special_members);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3057,6 +3057,14 @@ void Sema::CheckExplicitlyDefaultedDefaultConstructor(CXXConstructorDecl *CD) {
|
||||||
// We know there are no parameters.
|
// We know there are no parameters.
|
||||||
CD->setType(Context.getFunctionType(Context.VoidTy, 0, 0, EPI));
|
CD->setType(Context.getFunctionType(Context.VoidTy, 0, 0, EPI));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ShouldDeleteDefaultConstructor(CD)) {
|
||||||
|
if (First)
|
||||||
|
CD->setDeletedAsWritten();
|
||||||
|
else
|
||||||
|
Diag(CD->getLocation(), diag::err_out_of_line_default_deletes)
|
||||||
|
<< getSpecialMember(CD);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sema::ShouldDeleteDefaultConstructor(CXXConstructorDecl *CD) {
|
bool Sema::ShouldDeleteDefaultConstructor(CXXConstructorDecl *CD) {
|
||||||
|
|
Loading…
Reference in New Issue