[cfe-commits] r172510 - in /cfe/trunk: lib/Parse/ParseTemplate.cpp test/Parser/cxx11-brace-initializers.cpp

Richard Smith richard-llvm at metafoo.co.uk
Mon Jan 14 22:49:39 PST 2013


Author: rsmith
Date: Tue Jan 15 00:49:38 2013
New Revision: 172510

URL: http://llvm.org/viewvc/llvm-project?rev=172510&view=rev
Log:
PR14918: Don't confuse braced-init-lists after template variable declarations
with function definitions.

We really should remove Parser::isDeclarationAfterDeclarator entirely, since
it's meaningless in C++11 (an open brace could be either a function definition
or an initializer, which is what it's trying to differentiate between). The
other caller of it happens to be correct right now...

Modified:
    cfe/trunk/lib/Parse/ParseTemplate.cpp
    cfe/trunk/test/Parser/cxx11-brace-initializers.cpp

Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=172510&r1=172509&r2=172510&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTemplate.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTemplate.cpp Tue Jan 15 00:49:38 2013
@@ -240,27 +240,6 @@
   if (DeclaratorInfo.isFunctionDeclarator())
     MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs);
 
-  // If we have a declaration or declarator list, handle it.
-  if (isDeclarationAfterDeclarator()) {
-    // Parse this declaration.
-    Decl *ThisDecl = ParseDeclarationAfterDeclarator(DeclaratorInfo,
-                                                     TemplateInfo);
-
-    if (Tok.is(tok::comma)) {
-      Diag(Tok, diag::err_multiple_template_declarators)
-        << (int)TemplateInfo.Kind;
-      SkipUntil(tok::semi, true, false);
-      return ThisDecl;
-    }
-
-    // Eat the semi colon after the declaration.
-    ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
-    if (LateParsedAttrs.size() > 0)
-      ParseLexedAttributeList(LateParsedAttrs, ThisDecl, true, false);
-    DeclaratorInfo.complete(ThisDecl);
-    return ThisDecl;
-  }
-
   if (DeclaratorInfo.isFunctionDeclarator() &&
       isStartOfFunctionDefinition(DeclaratorInfo)) {
     if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
@@ -275,12 +254,23 @@
                                    &LateParsedAttrs);
   }
 
-  if (DeclaratorInfo.isFunctionDeclarator())
-    Diag(Tok, diag::err_expected_fn_body);
-  else
-    Diag(Tok, diag::err_invalid_token_after_toplevel_declarator);
-  SkipUntil(tok::semi);
-  return 0;
+  // Parse this declaration.
+  Decl *ThisDecl = ParseDeclarationAfterDeclarator(DeclaratorInfo,
+                                                   TemplateInfo);
+
+  if (Tok.is(tok::comma)) {
+    Diag(Tok, diag::err_multiple_template_declarators)
+      << (int)TemplateInfo.Kind;
+    SkipUntil(tok::semi, true, false);
+    return ThisDecl;
+  }
+
+  // Eat the semi colon after the declaration.
+  ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
+  if (LateParsedAttrs.size() > 0)
+    ParseLexedAttributeList(LateParsedAttrs, ThisDecl, true, false);
+  DeclaratorInfo.complete(ThisDecl);
+  return ThisDecl;
 }
 
 /// ParseTemplateParameters - Parses a template-parameter-list enclosed in

Modified: cfe/trunk/test/Parser/cxx11-brace-initializers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx11-brace-initializers.cpp?rev=172510&r1=172509&r2=172510&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx11-brace-initializers.cpp (original)
+++ cfe/trunk/test/Parser/cxx11-brace-initializers.cpp Tue Jan 15 00:49:38 2013
@@ -14,3 +14,14 @@
 
   f(0, {1, 1}, 0);
 }
+
+namespace PR14948 {
+  template<typename T> struct Q { static T x; };
+
+  struct X {};
+  template<> X Q<X>::x {};
+  template<> int Q<int[]>::x[] { 1, 2, 3 };
+  template<> int Q<int>::x { 1 };
+
+  template<typename T> T Q<T>::x {};
+}





More information about the cfe-commits mailing list