From 0f32caff4dc351719ca3362d95f859d72fdd6f1b Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 29 Sep 2011 22:45:21 +0000 Subject: [PATCH] Minor refactoring. Enumerators may inherit the deprecated/unavailable attributes from the enumeration type. // rdar://10201690 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140818 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/Sema.h | 3 +- lib/Sema/SemaExpr.cpp | 77 +++++++++++++++++++++------------------ 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index e7731fed42..f812556e0f 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -2222,8 +2222,7 @@ public: bool CanUseDecl(NamedDecl *D); bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, - const ObjCInterfaceDecl *UnknownObjCClass = 0, - const EnumDecl *EnumeratorEnumDecl = 0); + const ObjCInterfaceDecl *UnknownObjCClass=0); std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD); bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, ObjCMethodDecl *Getter, diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index f9d34a7fa3..0fea54b77d 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -56,6 +56,41 @@ bool Sema::CanUseDecl(NamedDecl *D) { return true; } +static AvailabilityResult DiagnoseAvailabilityOfDecl(Sema &S, + NamedDecl *D, SourceLocation Loc, + const ObjCInterfaceDecl *UnknownObjCClass) { + // See if this declaration is unavailable or deprecated. + std::string Message; + AvailabilityResult Result = D->getAvailability(&Message); + switch (Result) { + case AR_Available: + case AR_NotYetIntroduced: + break; + + case AR_Deprecated: + S.EmitDeprecationWarning(D, Message, Loc, UnknownObjCClass); + break; + + case AR_Unavailable: + if (cast(S.CurContext)->getAvailability() != AR_Unavailable) { + if (Message.empty()) { + if (!UnknownObjCClass) + S.Diag(Loc, diag::err_unavailable) << D->getDeclName(); + else + S.Diag(Loc, diag::warn_unavailable_fwdclass_message) + << D->getDeclName(); + } + else + S.Diag(Loc, diag::err_unavailable_message) + << D->getDeclName() << Message; + S.Diag(D->getLocation(), diag::note_unavailable_here) + << isa(D) << false; + } + break; + } + return Result; +} + /// \brief Determine whether the use of this declaration is valid, and /// emit any corresponding diagnostics. /// @@ -69,8 +104,7 @@ bool Sema::CanUseDecl(NamedDecl *D) { /// referenced), false otherwise. /// bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, - const ObjCInterfaceDecl *UnknownObjCClass, - const EnumDecl *EnumeratorEnumDecl) { + const ObjCInterfaceDecl *UnknownObjCClass) { if (getLangOptions().CPlusPlus && isa(D)) { // If there were any diagnostics suppressed by template argument deduction, // emit them now. @@ -104,39 +138,11 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, return true; } } - - // See if this declaration is unavailable or deprecated. - std::string Message; - AvailabilityResult Result = D->getAvailability(&Message); - switch (Result) { - case AR_Available: - case AR_NotYetIntroduced: - break; - - case AR_Deprecated: - EmitDeprecationWarning(D, Message, Loc, UnknownObjCClass); - break; - - case AR_Unavailable: - if (cast(CurContext)->getAvailability() != AR_Unavailable) { - if (Message.empty()) { - if (!UnknownObjCClass) - Diag(Loc, diag::err_unavailable) << D->getDeclName(); - else - Diag(Loc, diag::warn_unavailable_fwdclass_message) - << D->getDeclName(); - } - else - Diag(Loc, diag::err_unavailable_message) - << D->getDeclName() << Message; - Diag(D->getLocation(), diag::note_unavailable_here) - << isa(D) << false; - } - break; - } + AvailabilityResult Result = + DiagnoseAvailabilityOfDecl(*this, D, Loc, UnknownObjCClass); // Warn if this is used but marked unused. - if (D->hasAttr() && !EnumeratorEnumDecl) + if (D->hasAttr()) Diag(Loc, diag::warn_used_but_marked_unused) << D->getDeclName(); // For available enumerator, it will become unavailable/deprecated // if its enum declaration is as such. @@ -144,8 +150,9 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, if (const EnumConstantDecl *ECD = dyn_cast(D)) { const DeclContext *DC = ECD->getDeclContext(); if (const EnumDecl *TheEnumDecl = dyn_cast(DC)) - DiagnoseUseOfDecl(const_cast< EnumDecl *>(TheEnumDecl), - Loc, UnknownObjCClass, TheEnumDecl); + DiagnoseAvailabilityOfDecl(*this, + const_cast< EnumDecl *>(TheEnumDecl), + Loc, UnknownObjCClass); } return false; } -- 2.40.0