From 2b982b778d265c337af5d1b4c74ce49479cbda7d Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 25 Feb 2011 18:38:59 +0000 Subject: [PATCH] Print optional message for attr(unavailable) in C++ mode. // rdar://9046492 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126499 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ lib/Sema/SemaOverload.cpp | 23 +++++++++++++++++----- test/SemaCXX/attr-unavailable.cpp | 11 +++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 487b3c4d6a..3c00e8b5c3 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1312,6 +1312,8 @@ 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">; def err_ovl_ambiguous_member_call : Error< "call to member function %0 is ambiguous">; def err_ovl_deleted_member_call : Error< diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index c59bfec811..1da95b6a35 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -7709,11 +7709,24 @@ Sema::BuildOverloadedCallExpr(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, break; case OR_Deleted: - Diag(Fn->getSourceRange().getBegin(), diag::err_ovl_deleted_call) - << Best->Function->isDeleted() - << ULE->getName() - << Fn->getSourceRange(); - CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args, NumArgs); + { + 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(); + CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args, NumArgs); + } break; } diff --git a/test/SemaCXX/attr-unavailable.cpp b/test/SemaCXX/attr-unavailable.cpp index 6f5aa5e78c..81db505e1e 100644 --- a/test/SemaCXX/attr-unavailable.cpp +++ b/test/SemaCXX/attr-unavailable.cpp @@ -18,3 +18,14 @@ void test_foo(short* sp) { int &(*fp3)(int) = foo; void (*fp4)(...) = foo; // expected-error{{'foo' is unavailable}} } + +namespace radar9046492 { +// rdar://9046492 +#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}} +} +} -- 2.40.0