From: Fariborz Jahanian Date: Mon, 28 Nov 2011 19:45:58 +0000 (+0000) Subject: pinpoint name/location of deprecated/unavailable enumerator X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=39b4fc888d2b9b8fe1a9c982964b5054ba1c3c73;p=clang pinpoint name/location of deprecated/unavailable enumerator whose enum has been made deprecated/unavailable in the warning. // rdar://10201690 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145264 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index e6e6e5f5e1..cbfff90965 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -68,6 +68,13 @@ static AvailabilityResult DiagnoseAvailabilityOfDecl(Sema &S, // See if this declaration is unavailable or deprecated. std::string Message; AvailabilityResult Result = D->getAvailability(&Message); + if (const EnumConstantDecl *ECD = dyn_cast(D)) + if (Result == AR_Available) { + const DeclContext *DC = ECD->getDeclContext(); + if (const EnumDecl *TheEnumDecl = dyn_cast(DC)) + Result = TheEnumDecl->getAvailability(&Message); + } + switch (Result) { case AR_Available: case AR_NotYetIntroduced: @@ -158,7 +165,7 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, if (const EnumDecl *TheEnumDecl = dyn_cast(DC)) DiagnoseAvailabilityOfDecl(*this, const_cast< EnumDecl *>(TheEnumDecl), - Loc, UnknownObjCClass); + D->getLocation(), UnknownObjCClass); } return false; } diff --git a/test/Sema/attr-deprecated.c b/test/Sema/attr-deprecated.c index 2889f8fa11..86ee80ef06 100644 --- a/test/Sema/attr-deprecated.c +++ b/test/Sema/attr-deprecated.c @@ -109,7 +109,7 @@ enum __attribute__((deprecated)) Test20 { void test20() { enum Test20 f; // expected-warning {{'Test20' is deprecated}} f = test20_a; // expected-warning {{'test20_a' is deprecated}} - f = test20_b; // expected-warning {{'Test20' is deprecated}} + f = test20_b; // expected-warning {{'test20_b' is deprecated}} } char test21[__has_feature(attribute_deprecated_with_message) ? 1 : -1]; diff --git a/test/Sema/attr-unavailable-message.c b/test/Sema/attr-unavailable-message.c index 9b0c3debd8..208e0941b2 100644 --- a/test/Sema/attr-unavailable-message.c +++ b/test/Sema/attr-unavailable-message.c @@ -34,16 +34,16 @@ enum foo { c = 3 }__attribute__((deprecated())); -enum fee { // expected-note 2 {{declaration has been explicitly marked unavailable here}} - r = 1, +enum fee { // expected-note {{declaration has been explicitly marked unavailable here}} + r = 1, // expected-note {{declaration has been explicitly marked unavailable here}} s = 2, t = 3 }__attribute__((unavailable())); enum fee f() { // expected-error {{error: 'fee' is unavailable}} - int i = a; // expected-warning {{'foo' is deprecated }} + int i = a; // expected-warning {{'a' is deprecated }} i = b; // expected-warning {{'b' is deprecated}} - return r; // expected-error {{'fee' is unavailable}} + return r; // expected-error {{'r' is unavailable}} } diff --git a/test/SemaCXX/attr-deprecated.cpp b/test/SemaCXX/attr-deprecated.cpp index 945aff363e..46568aabd6 100644 --- a/test/SemaCXX/attr-deprecated.cpp +++ b/test/SemaCXX/attr-deprecated.cpp @@ -198,7 +198,7 @@ namespace test6 { }; void testA() { A x; // expected-warning {{'A' is deprecated}} - x = a0; // expected-warning {{'A' is deprecated}} + x = a0; // expected-warning {{'a0' is deprecated}} } enum B { @@ -218,7 +218,7 @@ namespace test6 { }; void testC() { C::Enum x; // expected-warning {{'Enum' is deprecated}} - x = C::c0; // expected-warning {{'Enum' is deprecated}} + x = C::c0; // expected-warning {{'c0' is deprecated}} } template struct D {