[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
Fariborz Jahanian
fjahanian at apple.com
Thu Sep 29 11:40:01 PDT 2011
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;
}
Modified: cfe/trunk/test/Sema/attr-deprecated.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-deprecated.c?rev=140800&r1=140799&r2=140800&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-deprecated.c (original)
+++ cfe/trunk/test/Sema/attr-deprecated.c Thu Sep 29 13:40:01 2011
@@ -109,7 +109,7 @@
void test20() {
enum Test20 f; // expected-warning {{'Test20' is deprecated}}
f = test20_a; // expected-warning {{'test20_a' is deprecated}}
- f = test20_b;
+ f = test20_b; // expected-warning {{'Test20' is deprecated}}
}
char test21[__has_feature(attribute_deprecated_with_message) ? 1 : -1];
Modified: cfe/trunk/test/Sema/attr-unavailable-message.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-unavailable-message.c?rev=140800&r1=140799&r2=140800&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-unavailable-message.c (original)
+++ cfe/trunk/test/Sema/attr-unavailable-message.c Thu Sep 29 13:40:01 2011
@@ -26,3 +26,24 @@
void (*fp)() = &bar;
double (*fp4)(double) = dfoo;
}
+
+// rdar://10201690
+enum foo {
+ a = 1,
+ b __attribute__((deprecated())) = 2,
+ c = 3
+}__attribute__((deprecated()));
+
+enum fee { // expected-note 2 {{declaration has been explicitly marked unavailable here}}
+ r = 1,
+ s = 2,
+ t = 3
+}__attribute__((unavailable()));
+
+enum fee f() { // expected-error {{error: 'fee' is unavailable}}
+ int i = a; // expected-warning {{'foo' is deprecated }}
+
+ i = b; // expected-warning {{'b' is deprecated}}
+
+ return r; // expected-error {{'fee' is unavailable}}
+}
Modified: cfe/trunk/test/SemaCXX/attr-deprecated.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-deprecated.cpp?rev=140800&r1=140799&r2=140800&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-deprecated.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-deprecated.cpp Thu Sep 29 13:40:01 2011
@@ -198,7 +198,7 @@
};
void testA() {
A x; // expected-warning {{'A' is deprecated}}
- x = a0;
+ x = a0; // expected-warning {{'A' is deprecated}}
}
enum B {
@@ -218,7 +218,7 @@
};
void testC() {
C<int>::Enum x; // expected-warning {{'Enum' is deprecated}}
- x = C<int>::c0;
+ x = C<int>::c0; // expected-warning {{'Enum' is deprecated}}
}
template <class T> struct D {
More information about the cfe-commits
mailing list