]> granicus.if.org Git - clang/commitdiff
It's okay to reference an enum in a template definition, even though
authorDouglas Gregor <dgregor@apple.com>
Mon, 3 May 2010 17:48:54 +0000 (17:48 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 3 May 2010 17:48:54 +0000 (17:48 +0000)
it's ill-formed to form an enum template. Fixes <rdar://problem/7933063>.

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

lib/Parse/ParseDecl.cpp
test/SemaTemplate/template-decl-fail.cpp

index 6669d40cca0d6fa67eb3ff6bdd16dc6496fd2c1f..91050e0a4cf9c271f6e2ad5e02689b4840262778 100644 (file)
@@ -1900,15 +1900,6 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
     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 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
     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;
index 7c04131eba271f5a8673d98ab7944c653e426959..ad134cdf225c2aba3f6dc14050b94ebb26605a27 100644 (file)
@@ -6,3 +6,5 @@ template<typename T>
 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) {}