]> granicus.if.org Git - clang/commitdiff
Fix a couple issues with parsing invalid nested-name-specifiers.
authorEli Friedman <eli.friedman@gmail.com>
Sat, 29 Aug 2009 04:08:08 +0000 (04:08 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 29 Aug 2009 04:08:08 +0000 (04:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80421 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExprCXX.cpp
test/SemaCXX/invalid-template-specifier.cpp [new file with mode: 0644]

index d97bc2d0288f353afa1eaf2f95390acf72da8536..e9cca9fe1d2f941291751cd4e089e2104a1ec2bb 100644 (file)
@@ -65,6 +65,12 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
     // Parse the optional 'template' keyword, then make sure we have
     // 'identifier <' after it.
     if (Tok.is(tok::kw_template)) {
+      // If we don't have a scope specifier, this isn't a
+      // nested-name-specifier, since they aren't allowed to start with
+      // 'template'.
+      if (!HasScopeSpecifier)
+        break;
+
       SourceLocation TemplateKWLoc = ConsumeToken();
       
       if (Tok.isNot(tok::identifier)) {
@@ -86,6 +92,8 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
         = Actions.ActOnDependentTemplateName(TemplateKWLoc,
                                              *Tok.getIdentifierInfo(),
                                              Tok.getLocation(), SS);
+      if (!Template)
+        break;
       if (AnnotateTemplateIdToken(Template, TNK_Dependent_template_name,
                                   &SS, TemplateKWLoc, false))
         break;
diff --git a/test/SemaCXX/invalid-template-specifier.cpp b/test/SemaCXX/invalid-template-specifier.cpp
new file mode 100644 (file)
index 0000000..a3f081f
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: clang-cc %s -verify -fsyntax-only
+// PR4809
+// This test is primarily checking that this doesn't crash, not the particular
+// diagnostics.
+
+const template basic_istream<char>; // expected-error {{expected unqualified-id}}
+
+namespace S {}
+template <class X> class Y {
+  void x() { S::template y<char>(1); } // expected-error {{does not refer to a template}} \
+                                       // expected-error {{no member named 'y'}}
+};