// 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)) {
= Actions.ActOnDependentTemplateName(TemplateKWLoc,
*Tok.getIdentifierInfo(),
Tok.getLocation(), SS);
+ if (!Template)
+ break;
if (AnnotateTemplateIdToken(Template, TNK_Dependent_template_name,
&SS, TemplateKWLoc, false))
break;
--- /dev/null
+// 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'}}
+};