summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-02-15 19:33:52 +0000
committerDouglas Gregor <dgregor@apple.com>2012-02-15 19:33:52 +0000
commit74f7d50f6a5b2f74bb63bedae2d32590b8f594ce (patch)
treede4af323c1622f239cbec188047ea74dd73c4017 /clang/lib/Sema
parent06b6812b5f0cb59507cc8ba30eada29c6c75d184 (diff)
downloadbcm5719-llvm-74f7d50f6a5b2f74bb63bedae2d32590b8f594ce.tar.gz
bcm5719-llvm-74f7d50f6a5b2f74bb63bedae2d32590b8f594ce.zip
When overload resolution picks an implicitly-deleted special member
function, provide a specialized diagnostic that indicates the kind of special member function (default constructor, copy assignment operator, etc.) and that it was implicitly deleted. Add a hook where we can provide more detailed information later. llvm-svn: 150611
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/AnalysisBasedWarnings.cpp1
-rw-r--r--clang/lib/Sema/SemaDeclCXX.cpp6
-rw-r--r--clang/lib/Sema/SemaInit.cpp48
-rw-r--r--clang/lib/Sema/SemaOverload.cpp23
4 files changed, 66 insertions, 12 deletions
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 2d609001d4e..bcb138118d7 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -219,7 +219,6 @@ struct CheckFallThroughDiagnostics {
unsigned diag_AlwaysFallThrough_ReturnsNonVoid;
unsigned diag_NeverFallThroughOrReturn;
enum { Function, Block, Lambda } funMode;
- bool IsLambda;
SourceLocation FuncLoc;
static CheckFallThroughDiagnostics MakeForFunction(const Decl *Func) {
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 624dc5d1e6f..447a4b42572 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -9045,6 +9045,12 @@ void Sema::DefineImplicitMoveConstructor(SourceLocation CurrentLocation,
}
}
+bool Sema::isImplicitlyDeleted(FunctionDecl *FD) {
+ return FD->isDeleted() &&
+ (FD->isDefaulted() || FD->isImplicit()) &&
+ isa<CXXMethodDecl>(FD);
+}
+
ExprResult
Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
CXXConstructorDecl *Constructor,
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 1638693a2c6..da6892e230d 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5273,6 +5273,26 @@ InitializationSequence::Perform(Sema &S,
return move(CurInit);
}
+/// \brief Provide some notes that detail why a function was implicitly
+/// deleted.
+static void diagnoseImplicitlyDeletedFunction(Sema &S, CXXMethodDecl *Method) {
+ // FIXME: This is a work in progress. It should dig deeper to figure out
+ // why the function was deleted (e.g., because one of its members doesn't
+ // have a copy constructor, for the copy-constructor case).
+ if (!Method->isImplicit()) {
+ S.Diag(Method->getLocation(), diag::note_callee_decl)
+ << Method->getDeclName();
+ }
+
+ if (Method->getParent()->isLambda()) {
+ S.Diag(Method->getParent()->getLocation(), diag::note_lambda_decl);
+ return;
+ }
+
+ S.Diag(Method->getParent()->getLocation(), diag::note_defined_here)
+ << Method->getParent();
+}
+
//===----------------------------------------------------------------------===//
// Diagnose initialization failures
//===----------------------------------------------------------------------===//
@@ -5536,17 +5556,33 @@ bool InitializationSequence::Diagnose(Sema &S,
break;
case OR_Deleted: {
- S.Diag(Kind.getLocation(), diag::err_ovl_deleted_init)
- << true << DestType << ArgsRange;
OverloadCandidateSet::iterator Best;
OverloadingResult Ovl
= FailedCandidateSet.BestViableFunction(S, Kind.getLocation(), Best);
- if (Ovl == OR_Deleted) {
- S.Diag(Best->Function->getLocation(), diag::note_unavailable_here)
- << 1 << Best->Function->isDeleted();
- } else {
+ if (Ovl != OR_Deleted) {
+ S.Diag(Kind.getLocation(), diag::err_ovl_deleted_init)
+ << true << DestType << ArgsRange;
llvm_unreachable("Inconsistent overload resolution?");
+ break;
}
+
+ // If this is a defaulted or implicitly-declared function, then
+ // it was implicitly deleted. Make it clear that the deletion was
+ // implicit.
+ if (S.isImplicitlyDeleted(Best->Function)) {
+ S.Diag(Kind.getLocation(), diag::err_ovl_deleted_special_init)
+ << S.getSpecialMember(cast<CXXMethodDecl>(Best->Function))
+ << DestType << ArgsRange;
+
+ diagnoseImplicitlyDeletedFunction(S,
+ cast<CXXMethodDecl>(Best->Function));
+ break;
+ }
+
+ S.Diag(Kind.getLocation(), diag::err_ovl_deleted_init)
+ << true << DestType << ArgsRange;
+ S.Diag(Best->Function->getLocation(), diag::note_unavailable_here)
+ << 1 << Best->Function->isDeleted();
break;
}
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index b20dc955c1d..2b025da0885 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -9984,11 +9984,24 @@ Sema::CreateOverloadedBinOp(SourceLocation OpLoc,
return ExprError();
case OR_Deleted:
- Diag(OpLoc, diag::err_ovl_deleted_oper)
- << Best->Function->isDeleted()
- << BinaryOperator::getOpcodeStr(Opc)
- << getDeletedOrUnavailableSuffix(Best->Function)
- << Args[0]->getSourceRange() << Args[1]->getSourceRange();
+ if (isImplicitlyDeleted(Best->Function)) {
+ CXXMethodDecl *Method = cast<CXXMethodDecl>(Best->Function);
+ Diag(OpLoc, diag::err_ovl_deleted_special_oper)
+ << getSpecialMember(Method)
+ << BinaryOperator::getOpcodeStr(Opc)
+ << getDeletedOrUnavailableSuffix(Best->Function);
+
+ if (Method->getParent()->isLambda()) {
+ Diag(Method->getParent()->getLocation(), diag::note_lambda_decl);
+ return ExprError();
+ }
+ } else {
+ Diag(OpLoc, diag::err_ovl_deleted_oper)
+ << Best->Function->isDeleted()
+ << BinaryOperator::getOpcodeStr(Opc)
+ << getDeletedOrUnavailableSuffix(Best->Function)
+ << Args[0]->getSourceRange() << Args[1]->getSourceRange();
+ }
CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args, 2,
BinaryOperator::getOpcodeStr(Opc), OpLoc);
return ExprError();
OpenPOWER on IntegriCloud