[cfe-commits] r86904 - in /cfe/trunk: lib/Lex/PPCaching.cpp lib/Parse/ParseTemplate.cpp test/SemaTemplate/default-arguments.cpp

Douglas Gregor dgregor at apple.com
Wed Nov 11 16:03:40 PST 2009


Author: dgregor
Date: Wed Nov 11 18:03:40 2009
New Revision: 86904

URL: http://llvm.org/viewvc/llvm-project?rev=86904&view=rev
Log:
Remove an overly-eager assertion when replacing tokens with an
annotation token, because some of the tokens we're annotating might
not be in the set of cached tokens (we could have consumed them
unconditionally).

Also, move the tentative parsing from ParseTemplateTemplateArgument
into the one caller that needs it, improving recovery.

Modified:
    cfe/trunk/lib/Lex/PPCaching.cpp
    cfe/trunk/lib/Parse/ParseTemplate.cpp
    cfe/trunk/test/SemaTemplate/default-arguments.cpp

Modified: cfe/trunk/lib/Lex/PPCaching.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPCaching.cpp?rev=86904&r1=86903&r2=86904&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPCaching.cpp (original)
+++ cfe/trunk/lib/Lex/PPCaching.cpp Wed Nov 11 18:03:40 2009
@@ -109,6 +109,4 @@
       return;
     }
   }
-
-  assert(0&&"Didn't find the first token represented by the annotation token!");
 }

Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=86904&r1=86903&r2=86904&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseTemplate.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTemplate.cpp Wed Nov 11 18:03:40 2009
@@ -823,15 +823,13 @@
   //   A template-argument for a template template-parameter shall be the name
   //   of a class template or a template alias, expressed as id-expression.
   //   
-  // We perform some tentative parsing at this point, to determine whether
-  // we have an id-expression that refers to a class template or template
-  // alias. The grammar we tentatively parse is:
+  // We parse an id-expression that refers to a class template or template
+  // alias. The grammar we parse is:
   //
   //   nested-name-specifier[opt] template[opt] identifier
   //
   // followed by a token that terminates a template argument, such as ',', 
   // '>', or (in some cases) '>>'.
-  TentativeParsingAction TPA(*this);
   CXXScopeSpec SS; // nested-name-specifier, if present
   ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, 
                                  /*EnteringContext=*/false);
@@ -854,10 +852,8 @@
         TemplateTy Template
         = Actions.ActOnDependentTemplateName(TemplateLoc, SS, Name, 
                                              /*ObjectType=*/0);
-        if (Template.get()) {
-          TPA.Commit();
+        if (Template.get())
           return ParsedTemplateArgument(SS, Template, Name.StartLocation);
-        }
       }
     } 
   } else if (Tok.is(tok::identifier)) {
@@ -875,16 +871,12 @@
       if (TNK == TNK_Dependent_template_name || TNK == TNK_Type_template) {
         // We have an id-expression that refers to a class template or
         // (C++0x) template alias. 
-        TPA.Commit();
         return ParsedTemplateArgument(SS, Template, Name.StartLocation);
       }
     }
   }
   
-  // We don't have a template template argument; revert everything we have
-  // tentatively parsed.
-  TPA.Revert();
-  
+  // We don't have a template template argument.  
   return ParsedTemplateArgument();
 }
 
@@ -912,10 +904,19 @@
   }
   
   // Try to parse a template template argument.
-  ParsedTemplateArgument TemplateTemplateArgument
-    = ParseTemplateTemplateArgument();
-  if (!TemplateTemplateArgument.isInvalid())
-    return TemplateTemplateArgument;
+  {
+    TentativeParsingAction TPA(*this);
+
+    ParsedTemplateArgument TemplateTemplateArgument
+      = ParseTemplateTemplateArgument();
+    if (!TemplateTemplateArgument.isInvalid()) {
+      TPA.Commit();
+      return TemplateTemplateArgument;
+    }
+    
+    // Revert this tentative parse to parse a non-type template argument.
+    TPA.Revert();
+  }
   
   // Parse a non-type template argument. 
   SourceLocation Loc = Tok.getLocation();

Modified: cfe/trunk/test/SemaTemplate/default-arguments.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/default-arguments.cpp?rev=86904&r1=86903&r2=86904&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/default-arguments.cpp (original)
+++ cfe/trunk/test/SemaTemplate/default-arguments.cpp Wed Nov 11 18:03:40 2009
@@ -118,3 +118,6 @@
 X6<int> x6a;
 X6<long> x6b; // expected-note{{while checking a default template argument}}
 X6<long, X5b> x6c;
+
+
+template<template<class> class X = B<int> > struct X7; // expected-error{{must be a class template}}





More information about the cfe-commits mailing list