From: Fariborz Jahanian Date: Fri, 25 Feb 2011 20:51:14 +0000 (+0000) Subject: Sprinkle optional text of the "unavailable' attribute X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5e24f2a4ad3a3623349f058e99c7c71e1c8d705f;p=clang Sprinkle optional text of the "unavailable' attribute where ever such attribute causes an error diagnostic. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126509 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index ec379c3707..31cee24df9 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -119,6 +119,14 @@ public: return getIdentifier() ? getIdentifier()->getName() : ""; } + llvm::StringRef getMessageUnavailableAttr(bool unavailable) const { + if (!unavailable) + return ""; + if (const UnavailableAttr *UA = getAttr()) + return UA->getMessage(); + return ""; + } + /// getNameAsString - Get a human-readable name for the declaration, even if /// it is one of the special kinds of names (C++ constructor, Objective-C /// selector, etc). Creating this name requires expensive string diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 3c00e8b5c3..a9fb2da001 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1311,13 +1311,11 @@ def err_ovl_no_viable_member_function_in_call : Error< def err_ovl_ambiguous_call : Error< "call to %0 is ambiguous">; def err_ovl_deleted_call : Error< - "call to %select{unavailable|deleted}0 function %1">; -def err_ovl_unavailable_call : Error< - "call to unavailable function %0: %1">; + "call to %select{unavailable|deleted}0 function %1 %2">; def err_ovl_ambiguous_member_call : Error< "call to member function %0 is ambiguous">; def err_ovl_deleted_member_call : Error< - "call to %select{unavailable|deleted}0 member function %1">; + "call to %select{unavailable|deleted}0 member function %1 %2">; def note_ovl_too_many_candidates : Note< "remaining %0 candidate%s0 omitted; " "pass -fshow-overloads=all to show them">; @@ -1469,7 +1467,7 @@ def err_ovl_ambiguous_oper_binary : Error< "use of overloaded operator '%0' is ambiguous (with operand types %1 and %2)">; def err_ovl_no_viable_oper : Error<"no viable overloaded '%0'">; def err_ovl_deleted_oper : Error< - "overload resolution selected %select{unavailable|deleted}0 operator '%1'">; + "overload resolution selected %select{unavailable|deleted}0 operator '%1' %2">; def err_ovl_no_viable_subscript : Error<"no viable overloaded operator[] for type %0">; def err_ovl_no_oper : @@ -1483,7 +1481,7 @@ def err_ovl_no_viable_object_call : Error< def err_ovl_ambiguous_object_call : Error< "call to object of type %0 is ambiguous">; def err_ovl_deleted_object_call : Error< - "call to %select{unavailable|deleted}0 function call operator in type %1">; + "call to %select{unavailable|deleted}0 function call operator in type %1 %2">; def note_ovl_surrogate_cand : Note<"conversion candidate of type %0">; def err_member_call_without_object : Error< "call to non-static member function without an object argument">; diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index c4af1d57f2..6dd7aabaa1 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -1387,7 +1387,10 @@ bool Sema::FindAllocationOverload(SourceLocation StartLoc, SourceRange Range, case OR_Deleted: Diag(StartLoc, diag::err_ovl_deleted_call) << Best->Function->isDeleted() - << Name << Range; + << Name + << Best->Function->getMessageUnavailableAttr( + !Best->Function->isDeleted()) + << Range; Candidates.NoteCandidates(*this, OCD_AllCandidates, Args, NumArgs); return true; } diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 56322d9583..8d03285ee4 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -7701,21 +7701,12 @@ Sema::BuildOverloadedCallExpr(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, case OR_Deleted: { - llvm::StringRef Message; - if (const UnavailableAttr *UA = - Best->Function->getAttr()) - Message = UA->getMessage(); - - if (Message.empty()) - Diag(Fn->getSourceRange().getBegin(), diag::err_ovl_deleted_call) - << Best->Function->isDeleted() - << ULE->getName() - << Fn->getSourceRange(); - else - Diag(Fn->getSourceRange().getBegin(), diag::err_ovl_unavailable_call) - << ULE->getName() - << Message - << Fn->getSourceRange(); + Diag(Fn->getSourceRange().getBegin(), diag::err_ovl_deleted_call) + << Best->Function->isDeleted() + << ULE->getName() + << Best->Function->getMessageUnavailableAttr( + !Best->Function->isDeleted()) + << Fn->getSourceRange(); CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args, NumArgs); } break; @@ -7897,6 +7888,8 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, unsigned OpcIn, Diag(OpLoc, diag::err_ovl_deleted_oper) << Best->Function->isDeleted() << UnaryOperator::getOpcodeStr(Opc) + << Best->Function->getMessageUnavailableAttr( + !Best->Function->isDeleted()) << Input->getSourceRange(); CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args, NumArgs); return ExprError(); @@ -8165,6 +8158,8 @@ Sema::CreateOverloadedBinOp(SourceLocation OpLoc, Diag(OpLoc, diag::err_ovl_deleted_oper) << Best->Function->isDeleted() << BinaryOperator::getOpcodeStr(Opc) + << Best->Function->getMessageUnavailableAttr( + !Best->Function->isDeleted()) << Args[0]->getSourceRange() << Args[1]->getSourceRange(); CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args, 2); return ExprError(); @@ -8313,6 +8308,8 @@ Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, case OR_Deleted: Diag(LLoc, diag::err_ovl_deleted_oper) << Best->Function->isDeleted() << "[]" + << Best->Function->getMessageUnavailableAttr( + !Best->Function->isDeleted()) << Args[0]->getSourceRange() << Args[1]->getSourceRange(); CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args, 2, "[]", LLoc); @@ -8429,7 +8426,10 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE, case OR_Deleted: Diag(UnresExpr->getMemberLoc(), diag::err_ovl_deleted_member_call) << Best->Function->isDeleted() - << DeclName << MemExprE->getSourceRange(); + << DeclName + << Best->Function->getMessageUnavailableAttr( + !Best->Function->isDeleted()) + << MemExprE->getSourceRange(); CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args, NumArgs); // FIXME: Leaking incoming expressions! return ExprError(); @@ -8601,7 +8601,10 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, Diag(Object->getSourceRange().getBegin(), diag::err_ovl_deleted_object_call) << Best->Function->isDeleted() - << Object->getType() << Object->getSourceRange(); + << Object->getType() + << Best->Function->getMessageUnavailableAttr( + !Best->Function->isDeleted()) + << Object->getSourceRange(); CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args, NumArgs); break; } @@ -8807,7 +8810,10 @@ Sema::BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc) { case OR_Deleted: Diag(OpLoc, diag::err_ovl_deleted_oper) << Best->Function->isDeleted() - << "->" << Base->getSourceRange(); + << "->" + << Best->Function->getMessageUnavailableAttr( + !Best->Function->isDeleted()) + << Base->getSourceRange(); CandidateSet.NoteCandidates(*this, OCD_AllCandidates, &Base, 1); return ExprError(); } diff --git a/test/SemaCXX/attr-unavailable.cpp b/test/SemaCXX/attr-unavailable.cpp index 81db505e1e..fe3e8b1470 100644 --- a/test/SemaCXX/attr-unavailable.cpp +++ b/test/SemaCXX/attr-unavailable.cpp @@ -24,8 +24,7 @@ namespace radar9046492 { #define FOO __attribute__((unavailable("not available - replaced"))) void foo() FOO; // expected-note {{candidate function has been explicitly made unavailable}} - void bar() { - foo(); // expected-error {{call to unavailable function 'foo': not available - replaced}} + foo(); // expected-error {{call to unavailable function 'foo' not available - replaced}} } }