[cfe-commits] r140800 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaExpr.cpp test/Sema/attr-deprecated.c test/Sema/attr-unavailable-message.c test/SemaCXX/attr-deprecated.cpp
John McCall
rjmccall at apple.com
Thu Sep 29 13:37:29 PDT 2011
On Sep 29, 2011, at 11:40 AM, Fariborz Jahanian wrote:
> Author: fjahanian
> Date: Thu Sep 29 13:40:01 2011
> New Revision: 140800
>
> URL: http://llvm.org/viewvc/llvm-project?rev=140800&view=rev
> Log:
> c - Enumerators may inherit the deprecated/unavailable
> attributes from the enumeration type.
> // rdar://10201690
>
> Modified:
> cfe/trunk/include/clang/Sema/Sema.h
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/test/Sema/attr-deprecated.c
> cfe/trunk/test/Sema/attr-unavailable-message.c
> cfe/trunk/test/SemaCXX/attr-deprecated.cpp
>
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=140800&r1=140799&r2=140800&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Thu Sep 29 13:40:01 2011
> @@ -2222,7 +2222,8 @@
>
> bool CanUseDecl(NamedDecl *D);
> bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
> - const ObjCInterfaceDecl *UnknownObjCClass = 0);
> + const ObjCInterfaceDecl *UnknownObjCClass = 0,
> + const EnumDecl *EnumeratorEnumDecl = 0);
> std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD);
> bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
> ObjCMethodDecl *Getter,
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=140800&r1=140799&r2=140800&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep 29 13:40:01 2011
> @@ -69,7 +69,8 @@
> /// referenced), false otherwise.
> ///
> bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
> - const ObjCInterfaceDecl *UnknownObjCClass) {
> + const ObjCInterfaceDecl *UnknownObjCClass,
> + const EnumDecl *EnumeratorEnumDecl) {
> if (getLangOptions().CPlusPlus && isa<FunctionDecl>(D)) {
> // If there were any diagnostics suppressed by template argument deduction,
> // emit them now.
> @@ -106,11 +107,12 @@
>
> // See if this declaration is unavailable or deprecated.
> std::string Message;
> - switch (D->getAvailability(&Message)) {
> + AvailabilityResult Result = D->getAvailability(&Message);
> + switch (Result) {
> case AR_Available:
> case AR_NotYetIntroduced:
> break;
> -
> +
> case AR_Deprecated:
> EmitDeprecationWarning(D, Message, Loc, UnknownObjCClass);
> break;
> @@ -134,9 +136,17 @@
> }
>
> // Warn if this is used but marked unused.
> - if (D->hasAttr<UnusedAttr>())
> + if (D->hasAttr<UnusedAttr>() && !EnumeratorEnumDecl)
> 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.
> + if (Result == AR_Available)
> + if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(D)) {
> + const DeclContext *DC = ECD->getDeclContext();
> + if (const EnumDecl *TheEnumDecl = dyn_cast<EnumDecl>(DC))
> + DiagnoseUseOfDecl(const_cast< EnumDecl *>(TheEnumDecl),
> + Loc, UnknownObjCClass, TheEnumDecl);
> + }
> return false;
> }
The recursive invocation here is weird; why not just split out most of the checking into a helper function?
John.
More information about the cfe-commits
mailing list