]> granicus.if.org Git - clang/commitdiff
c - Enumerators may inherit the deprecated/unavailable
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 29 Sep 2011 18:40:01 +0000 (18:40 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 29 Sep 2011 18:40:01 +0000 (18:40 +0000)
attributes from the enumeration type.
// rdar://10201690

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140800 91177308-0d34-0410-b5e6-96231b3b80d8

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

index bb7521b243650476dd3edf411290b6d732eb7d14..e7731fed42bd46af62cc48c77b4cbc751548b223 100644 (file)
@@ -2222,7 +2222,8 @@ public:
 
   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,
index 2b67b4dc486ead79f58df016852e44a274b1f072..f9d34a7fa32dc60719bf6e539b461a00c02e1381 100644 (file)
@@ -69,7 +69,8 @@ bool Sema::CanUseDecl(NamedDecl *D) {
 /// 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 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
 
   // 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 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
   }
 
   // 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;
 }
 
index eeef0d757a700f2204120028eae9f26a44a98e9b..2889f8fa11460aee373eea9c225fd08f51135a2d 100644 (file)
@@ -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;
+  f = test20_b; // expected-warning {{'Test20' is deprecated}}
 }
 
 char test21[__has_feature(attribute_deprecated_with_message) ? 1 : -1];
index 9f663fc4efd4bff86333724e73dce0803993d707..9b0c3debd8a70f6be3a101503e7695f4c5aac18d 100644 (file)
@@ -26,3 +26,24 @@ void unavail(void) {
   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}}
+}
index fe7c833d322beebbc7c54ff7203a26bceffe6b06..945aff363eb154d3feb63c5160ed3616bb79d2a5 100644 (file)
@@ -198,7 +198,7 @@ namespace test6 {
   };
   void testA() {
     A x; // expected-warning {{'A' is deprecated}}
-    x = a0;
+    x = a0; // expected-warning {{'A' is deprecated}}
   }
   
   enum B {
@@ -218,7 +218,7 @@ namespace test6 {
   };
   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 {