[cfe-commits] r142928 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseDeclCXX.cpp test/CXX/class.derived/p1.cpp

David Blaikie dblaikie at gmail.com
Tue Oct 25 10:10:12 PDT 2011


Author: dblaikie
Date: Tue Oct 25 12:10:12 2011
New Revision: 142928

URL: http://llvm.org/viewvc/llvm-project?rev=142928&view=rev
Log:
Fix cases where the optional nested-name-specifier erroneously preceeded a decltype-specification when specifying a base type.

Modified:
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/test/CXX/class.derived/p1.cpp

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=142928&r1=142927&r2=142928&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Tue Oct 25 12:10:12 2011
@@ -2012,8 +2012,8 @@
 
   //===--------------------------------------------------------------------===//
   // C++ 10: Derived classes [class.derived]
-  TypeResult ParseBaseTypeSpecifier(SourceLocation &EndLocation, 
-                                    CXXScopeSpec &SS);
+  TypeResult ParseBaseTypeSpecifier(SourceLocation &BaseLoc, 
+                                    SourceLocation &EndLocation);
   void ParseBaseClause(Decl *ClassDecl);
   BaseResult ParseBaseSpecifier(Decl *ClassDecl);
   AccessSpecifier getAccessSpecifierIfPresent() const;

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=142928&r1=142927&r2=142928&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Tue Oct 25 12:10:12 2011
@@ -711,8 +711,26 @@
 ///         identifier
 ///         simple-template-id
 ///
-Parser::TypeResult Parser::ParseBaseTypeSpecifier(SourceLocation &EndLocation,
-                                                  CXXScopeSpec &SS) {
+Parser::TypeResult Parser::ParseBaseTypeSpecifier(SourceLocation &BaseLoc,
+                                                  SourceLocation &EndLocation) {
+  // Parse decltype-specifier
+  if (Tok.is(tok::kw_decltype)) {
+    // Fake up a Declarator to use with ActOnTypeName.
+    DeclSpec DS(AttrFactory);
+
+    ParseDecltypeSpecifier(DS);    
+    EndLocation = DS.getSourceRange().getEnd();
+
+    Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
+    return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
+  }
+
+  // Parse optional nested-name-specifier
+  CXXScopeSpec SS;
+  ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false);
+
+  BaseLoc = Tok.getLocation();
+
   // Check whether we have a template-id that names a type.
   if (Tok.is(tok::annot_template_id)) {
     TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
@@ -733,17 +751,6 @@
     // Fall through to produce an error below.
   }
 
-  if (Tok.is(tok::kw_decltype)) {
-    // Fake up a Declarator to use with ActOnTypeName.
-    DeclSpec DS(AttrFactory);
-
-    ParseDecltypeSpecifier(DS);    
-    EndLocation = DS.getSourceRange().getEnd();
-
-    Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
-    return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
-  }
-
   if (Tok.isNot(tok::identifier)) {
     Diag(Tok, diag::err_expected_class_name);
     return true;
@@ -1410,16 +1417,10 @@
     IsVirtual = true;
   }
 
-  // Parse optional '::' and optional nested-name-specifier.
-  CXXScopeSpec SS;
-  ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false);
-
-  // The location of the base class itself.
-  SourceLocation BaseLoc = Tok.getLocation();
-
   // Parse the class-name.
   SourceLocation EndLocation;
-  TypeResult BaseType = ParseBaseTypeSpecifier(EndLocation, SS);
+  SourceLocation BaseLoc;
+  TypeResult BaseType = ParseBaseTypeSpecifier(BaseLoc, EndLocation);
   if (BaseType.isInvalid())
     return true;
 

Modified: cfe/trunk/test/CXX/class.derived/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class.derived/p1.cpp?rev=142928&r1=142927&r2=142928&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class.derived/p1.cpp (original)
+++ cfe/trunk/test/CXX/class.derived/p1.cpp Tue Oct 25 12:10:12 2011
@@ -30,4 +30,8 @@
   struct Derived3 : decltype(T().foo()) { };
   struct Foo { Base foo(); };
   Derived3<Foo> d;
+
+  struct Derived4 : :: decltype(Base()) { }; // expected-error {{expected class name}}
+
+  struct Derived5 : PR11216:: decltype(Base()) { }; // expected-error {{expected class name}}
 }





More information about the cfe-commits mailing list