[cfe-commits] r117182 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Parse/ParseDecl.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/Sema/attr-deprecated.c test/SemaCXX/attr-deprecated.cpp

John McCall rjmccall at apple.com
Fri Oct 22 16:36:17 PDT 2010


Author: rjmccall
Date: Fri Oct 22 18:36:17 2010
New Revision: 117182

URL: http://llvm.org/viewvc/llvm-project?rev=117182&view=rev
Log:
Parse attributes on enumerators and instantiate attributes on enum decls.


Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/Sema/attr-deprecated.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=117182&r1=117181&r2=117182&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Oct 22 18:36:17 2010
@@ -882,6 +882,7 @@
 
   Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant,
                           SourceLocation IdLoc, IdentifierInfo *Id,
+                          AttributeList *Attrs,
                           SourceLocation EqualLoc, Expr *Val);
   void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
                      SourceLocation RBraceLoc, Decl *EnumDecl,

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=117182&r1=117181&r2=117182&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Oct 22 18:36:17 2010
@@ -2124,6 +2124,11 @@
     IdentifierInfo *Ident = Tok.getIdentifierInfo();
     SourceLocation IdentLoc = ConsumeToken();
 
+    // If attributes exist after the enumerator, parse them.
+    llvm::OwningPtr<AttributeList> Attr;
+    if (Tok.is(tok::kw___attribute))
+      Attr.reset(ParseGNUAttributes());
+
     SourceLocation EqualLoc;
     ExprResult AssignedVal;
     if (Tok.is(tok::equal)) {
@@ -2137,7 +2142,7 @@
     Decl *EnumConstDecl = Actions.ActOnEnumConstant(getCurScope(), EnumDecl,
                                                     LastEnumConstDecl,
                                                     IdentLoc, Ident,
-                                                    EqualLoc,
+                                                    Attr.get(), EqualLoc,
                                                     AssignedVal.release());
     EnumConstantDecls.push_back(EnumConstDecl);
     LastEnumConstDecl = EnumConstDecl;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=117182&r1=117181&r2=117182&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Oct 22 18:36:17 2010
@@ -7229,11 +7229,10 @@
 }
 
 
-Decl *Sema::ActOnEnumConstant(Scope *S, Decl *theEnumDecl,
-                                        Decl *lastEnumConst,
-                                        SourceLocation IdLoc,
-                                        IdentifierInfo *Id,
-                                        SourceLocation EqualLoc, ExprTy *val) {
+Decl *Sema::ActOnEnumConstant(Scope *S, Decl *theEnumDecl, Decl *lastEnumConst,
+                              SourceLocation IdLoc, IdentifierInfo *Id,
+                              AttributeList *Attr,
+                              SourceLocation EqualLoc, ExprTy *val) {
   EnumDecl *TheEnumDecl = cast<EnumDecl>(theEnumDecl);
   EnumConstantDecl *LastEnumConst =
     cast_or_null<EnumConstantDecl>(lastEnumConst);
@@ -7280,11 +7279,14 @@
     if (Record->getIdentifier() && Record->getIdentifier() == Id)
       Diag(IdLoc, diag::err_member_name_of_class) << Id;
   
-  EnumConstantDecl *New = CheckEnumConstant(TheEnumDecl, LastEnumConst,
-                                            IdLoc, Id, Val);
+  EnumConstantDecl *New =
+    CheckEnumConstant(TheEnumDecl, LastEnumConst, IdLoc, Id, Val);
 
-  // Register this decl in the current scope stack.
   if (New) {
+    // Process attributes.
+    if (Attr) ProcessDeclAttributeList(S, New, Attr);
+
+    // Register this decl in the current scope stack.
     New->setAccess(TheEnumDecl->getAccess());
     PushOnScopeChains(New, S);
   }

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=117182&r1=117181&r2=117182&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri Oct 22 18:36:17 2010
@@ -619,6 +619,8 @@
     }
   }
 
+  SemaRef.InstantiateAttrs(TemplateArgs, D, Enum);
+
   Enum->setInstantiationOfMemberEnum(D);
   Enum->setAccess(D->getAccess());
   if (SubstQualifier(D, Enum)) return 0;
@@ -663,6 +665,8 @@
     }
 
     if (EnumConst) {
+      SemaRef.InstantiateAttrs(TemplateArgs, *EC, EnumConst);
+
       EnumConst->setAccess(Enum->getAccess());
       Enum->addDecl(EnumConst);
       Enumerators.push_back(EnumConst);

Modified: cfe/trunk/test/Sema/attr-deprecated.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-deprecated.c?rev=117182&r1=117181&r2=117182&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-deprecated.c (original)
+++ cfe/trunk/test/Sema/attr-deprecated.c Fri Oct 22 18:36:17 2010
@@ -98,3 +98,14 @@
 foo_dep test17, // expected-warning {{'foo_dep' is deprecated}}
         test18 __attribute__((deprecated)),
         test19;
+
+// rdar://problem/8518751
+enum __attribute__((deprecated)) Test20 {
+  test20_a __attribute__((deprecated)),
+  test20_b
+};
+void test20() {
+  enum Test20 f; // expected-warning {{'Test20' is deprecated}}
+  f = test20_a; // expected-warning {{'test20_a' is deprecated}}
+  f = test20_b;
+}

Modified: cfe/trunk/test/SemaCXX/attr-deprecated.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-deprecated.cpp?rev=117182&r1=117181&r2=117182&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-deprecated.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-deprecated.cpp Fri Oct 22 18:36:17 2010
@@ -190,3 +190,46 @@
     {}
   };
 }
+
+// rdar://problem/8518751
+namespace test6 {
+  enum __attribute__((deprecated)) A {
+    a0
+  };
+  void testA() {
+    A x; // expected-warning {{'A' is deprecated}}
+    x = a0;
+  }
+  
+  enum B {
+    b0 __attribute__((deprecated)),
+    b1
+  };
+  void testB() {
+    B x;
+    x = b0; // expected-warning {{'b0' is deprecated}}
+    x = b1;
+  }
+
+  template <class T> struct C {
+    enum __attribute__((deprecated)) Enum {
+      c0
+    };
+  };
+  void testC() {
+    C<int>::Enum x; // expected-warning {{'Enum' is deprecated}}
+    x = C<int>::c0;
+  }
+
+  template <class T> struct D {
+    enum Enum {
+      d0,
+      d1 __attribute__((deprecated)),
+    };
+  };
+  void testD() {
+    D<int>::Enum x;
+    x = D<int>::d0;
+    x = D<int>::d1; // expected-warning {{'d1' is deprecated}}
+  }
+}





More information about the cfe-commits mailing list