[cfe-commits] r102926 - in /cfe/trunk: lib/Parse/ParseDecl.cpp test/SemaTemplate/template-decl-fail.cpp

Douglas Gregor dgregor at apple.com
Mon May 3 10:48:54 PDT 2010


Author: dgregor
Date: Mon May  3 12:48:54 2010
New Revision: 102926

URL: http://llvm.org/viewvc/llvm-project?rev=102926&view=rev
Log:
It's okay to reference an enum in a template definition, even though
it's ill-formed to form an enum template. Fixes <rdar://problem/7933063>.

Modified:
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/test/SemaTemplate/template-decl-fail.cpp

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=102926&r1=102925&r2=102926&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon May  3 12:48:54 2010
@@ -1900,15 +1900,6 @@
     return;
   }
 
-  // enums cannot be templates.
-  if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) {
-    Diag(Tok, diag::err_enum_template);
-
-    // Skip the rest of this declarator, up until the comma or semicolon.
-    SkipUntil(tok::comma, true);
-    return;      
-  }
-
   // If an identifier is present, consume and remember it.
   IdentifierInfo *Name = 0;
   SourceLocation NameLoc;
@@ -1932,6 +1923,18 @@
     TUK = Action::TUK_Declaration;
   else
     TUK = Action::TUK_Reference;
+  
+  // enums cannot be templates, although they can be referenced from a 
+  // template.
+  if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
+      TUK != Action::TUK_Reference) {
+    Diag(Tok, diag::err_enum_template);
+    
+    // Skip the rest of this declarator, up until the comma or semicolon.
+    SkipUntil(tok::comma, true);
+    return;      
+  }
+  
   bool Owned = false;
   bool IsDependent = false;
   SourceLocation TSTLoc = NameLoc.isValid()? NameLoc : StartLoc;

Modified: cfe/trunk/test/SemaTemplate/template-decl-fail.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/template-decl-fail.cpp?rev=102926&r1=102925&r2=102926&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/template-decl-fail.cpp (original)
+++ cfe/trunk/test/SemaTemplate/template-decl-fail.cpp Mon May  3 12:48:54 2010
@@ -6,3 +6,5 @@
 enum t0 { A = T::x }; // expected-error{{enumeration cannot be a template}} \
                       // expected-warning{{declaration does not declare anything}}
 
+enum e0 {};
+template<int x> enum e0 f0(int a=x) {}





More information about the cfe-commits mailing list