Fix an assertion-on-error during tentative constructor parsing by
propagating error conditions out of the various annotate-me-a-snowflake
routines.  Generally (but not universally) removes redundant diagnostics
as well as, you know, not crashing on bad code.  On the other hand,
I have just signed myself up to fix fiddly parser errors for the next
week.  Again.

llvm-svn: 97221
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 2416237..a6ae9cf 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -891,8 +891,7 @@
 /// specifier, and another one to get the actual type inside
 /// ParseDeclarationSpecifiers).
 ///
-/// This returns true if the token was annotated or an unrecoverable error
-/// occurs.
+/// This returns true if an error occurred.
 ///
 /// Note that this routine emits an error if you call it with ::new or ::delete
 /// as the current tokens, so only call it in contexts where these are invalid.
@@ -910,11 +909,11 @@
     //            simple-template-id
     SourceLocation TypenameLoc = ConsumeToken();
     CXXScopeSpec SS;
-    bool HadNestedNameSpecifier
-      = ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, false);
-    if (!HadNestedNameSpecifier) {
+    if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, false))
+      return true;
+    if (!SS.isSet()) {
       Diag(Tok.getLocation(), diag::err_expected_qualified_after_typename);
-      return false;
+      return true;
     }
 
     TypeResult Ty;
@@ -928,7 +927,7 @@
       if (TemplateId->Kind == TNK_Function_template) {
         Diag(Tok, diag::err_typename_refers_to_non_type_template)
           << Tok.getAnnotationRange();
-        return false;
+        return true;
       }
 
       AnnotateTemplateIdTokenAsType(0);
@@ -942,7 +941,7 @@
     } else {
       Diag(Tok, diag::err_expected_type_name_after_typename)
         << SS.getRange();
-      return false;
+      return true;
     }
 
     SourceLocation EndLoc = Tok.getLastLoc();
@@ -951,7 +950,7 @@
     Tok.setAnnotationEndLoc(EndLoc);
     Tok.setLocation(TypenameLoc);
     PP.AnnotateCachedTokens(Tok);
-    return true;
+    return false;
   }
 
   // Remembers whether the token was originally a scope annotation.
@@ -959,7 +958,8 @@
 
   CXXScopeSpec SS;
   if (getLang().CPlusPlus)
-    ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, EnteringContext);
+    if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, EnteringContext))
+      return true;
 
   if (Tok.is(tok::identifier)) {
     // Determine whether the identifier is a type name.
@@ -976,7 +976,7 @@
       // In case the tokens were cached, have Preprocessor replace
       // them with the annotation token.
       PP.AnnotateCachedTokens(Tok);
-      return true;
+      return false;
     }
 
     if (!getLang().CPlusPlus) {
@@ -1001,7 +1001,7 @@
           // If an unrecoverable error occurred, we need to return true here,
           // because the token stream is in a damaged state.  We may not return
           // a valid identifier.
-          return Tok.isNot(tok::identifier);
+          return true;
         }
       }
     }
@@ -1021,12 +1021,12 @@
       // to produce a type annotation token. Update the template-id
       // annotation token to a type annotation token now.
       AnnotateTemplateIdTokenAsType(&SS);
-      return true;
+      return false;
     }
   }
 
   if (SS.isEmpty())
-    return Tok.isNot(tok::identifier) && Tok.isNot(tok::coloncolon);
+    return false;
 
   // A C++ scope specifier that isn't followed by a typename.
   // Push the current token back into the token stream (or revert it if it is
@@ -1044,7 +1044,7 @@
   // just reverted back to the state we were in before being called.
   if (!wasScopeAnnotation)
     PP.AnnotateCachedTokens(Tok);
-  return true;
+  return false;
 }
 
 /// TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only
@@ -1061,10 +1061,10 @@
          "Cannot be a type or scope token!");
 
   CXXScopeSpec SS;
-  if (!ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, EnteringContext))
-    // If the token left behind is not an identifier, we either had an error or
-    // successfully turned it into an annotation token.
-    return Tok.isNot(tok::identifier);
+  if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, EnteringContext))
+    return true;
+  if (!SS.isSet())
+    return false;
 
   // Push the current token back into the token stream (or revert it if it is
   // cached) and use an annotation scope token for current token.
@@ -1079,7 +1079,7 @@
   // In case the tokens were cached, have Preprocessor replace them with the
   // annotation token.
   PP.AnnotateCachedTokens(Tok);
-  return true;
+  return false;
 }
 
 // Anchor the Parser::FieldCallback vtable to this translation unit.