[cfe-commits] r126509 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprCXX.cpp lib/Sema/SemaOverload.cpp test/SemaCXX/attr-unavailable.cpp

Fariborz Jahanian fjahanian at apple.com
Fri Feb 25 12:51:15 PST 2011


Author: fjahanian
Date: Fri Feb 25 14:51:14 2011
New Revision: 126509

URL: http://llvm.org/viewvc/llvm-project?rev=126509&view=rev
Log:
Sprinkle optional text of the "unavailable' attribute
where ever such attribute causes an error diagnostic.


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

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=126509&r1=126508&r2=126509&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Fri Feb 25 14:51:14 2011
@@ -119,6 +119,14 @@
     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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=126509&r1=126508&r2=126509&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Feb 25 14:51:14 2011
@@ -1311,13 +1311,11 @@
 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 @@
   "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_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">;

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=126509&r1=126508&r2=126509&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Feb 25 14:51:14 2011
@@ -1387,7 +1387,10 @@
   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;
   }

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=126509&r1=126508&r2=126509&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Feb 25 14:51:14 2011
@@ -7701,21 +7701,12 @@
 
   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 @@
       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 @@
       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 @@
     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 @@
     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 @@
     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 @@
   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();
   }

Modified: cfe/trunk/test/SemaCXX/attr-unavailable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-unavailable.cpp?rev=126509&r1=126508&r2=126509&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-unavailable.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-unavailable.cpp Fri Feb 25 14:51:14 2011
@@ -24,8 +24,7 @@
 #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}}
 }
 }





More information about the cfe-commits mailing list