]> granicus.if.org Git - clang/commitdiff
Sprinkle optional text of the "unavailable' attribute
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 25 Feb 2011 20:51:14 +0000 (20:51 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 25 Feb 2011 20:51:14 +0000 (20:51 +0000)
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

include/clang/AST/Decl.h
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExprCXX.cpp
lib/Sema/SemaOverload.cpp
test/SemaCXX/attr-unavailable.cpp

index ec379c3707233aeddfa3fffef68522ca62d5e108..31cee24df99382f8daf6d1c26ca30af896ce0a61 100644 (file)
@@ -119,6 +119,14 @@ public:
     return getIdentifier() ? getIdentifier()->getName() : "";
   }
 
+  llvm::StringRef getMessageUnavailableAttr(bool unavailable) const {
+    if (!unavailable)
+      return "";
+    if (const UnavailableAttr *UA = getAttr<UnavailableAttr>())
+      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
index 3c00e8b5c3b8e70d2416fcdaacdc25a43f95c643..a9fb2da0017658049e351e1272a023a384e43a7f 100644 (file)
@@ -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">;
index c4af1d57f2337f27e04589f07ff44ace77bc28ac..6dd7aabaa1f01a06eeafb4f9d456bebc6b9465aa 100644 (file)
@@ -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;
   }
index 56322d9583b0c51a8d1a9e7dd38e0368451b674d..8d03285ee4436b42f3d8c174365532c035d10af0 100644 (file)
@@ -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<UnavailableAttr>()) 
-        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();
   }
index 81db505e1e221af06f9e762765cf345e5f142250..fe3e8b14706fca17937eed4c1f4660de7457d90b 100644 (file)
@@ -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}}
 }
 }