diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index e62be697893477179ea682cd86ba6d0fcf1d5b16..64465bf66e2d0fbbf88594c1b4b5f9b3a3a9af33 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -920,8 +920,13 @@ Parser::TypeResult Parser::ParseBaseTypeSpecifier(SourceLocation &BaseLoc, << Id; } - if (!Template) + if (!Template) { + TemplateArgList TemplateArgs; + SourceLocation LAngleLoc, RAngleLoc; + ParseTemplateIdAfterTemplateName(TemplateTy(), IdLoc, SS, + true, LAngleLoc, TemplateArgs, RAngleLoc); return true; + } // Form the template name UnqualifiedId TemplateName; diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp index 92c59b029f9b178ccc2d955e75edad5d17f8d349..5ab5cec0289b8b9ff0adc178025b6a533ffa0bbf 100644 --- a/clang/lib/Parse/ParseTemplate.cpp +++ b/clang/lib/Parse/ParseTemplate.cpp @@ -679,6 +679,8 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) { /// \param RAngleLoc the location of the consumed '>'. /// /// \param ConsumeLastToken if true, the '>' is not consumed. +/// +/// \returns true, if current token does not start with '>', false otherwise. bool Parser::ParseGreaterThanInTemplateList(SourceLocation &RAngleLoc, bool ConsumeLastToken) { // What will be left once we've consumed the '>'. diff --git a/clang/test/Parser/cxx-template-argument.cpp b/clang/test/Parser/cxx-template-argument.cpp index a2c69be64630a97741186f00055f74f2cdd6fccc..8bf2a4f78addbd6b0c95f57d1819390644c862c0 100644 --- a/clang/test/Parser/cxx-template-argument.cpp +++ b/clang/test/Parser/cxx-template-argument.cpp @@ -42,3 +42,66 @@ namespace PR13210 { new C(); // expected-error {{requires template arguments}} } } + +// Don't emit spurious messages +namespace pr16225add { + + template struct Known { }; // expected-note 3 {{template is declared here}} + template struct X; + template struct ABC; // expected-note {{template is declared here}} + template struct ABC2 {}; + + template struct foo : + UnknownBase // expected-error {{unknown template name 'UnknownBase'}} + { }; + + template struct foo2 : + UnknownBase, // expected-error {{unknown template name 'UnknownBase'}} + Known // expected-error {{too few template arguments for class template 'Known'}} + { }; + + template struct foo3 : + UnknownBase > // expected-error {{unknown template name 'UnknownBase'}} + { }; + + template struct foo4 : + UnknownBase >, // expected-error {{unknown template name 'UnknownBase'}} \ + // expected-error {{too few template arguments for class template 'ABC'}} + Known // expected-error {{too few template arguments for class template 'Known'}} + { }; + + template struct foo5 : + UnknownBase> // expected-error {{unknown template name 'UnknownBase'}} \ + // expected-error {{use '> >'}} + { }; + + template struct foo6 : + UnknownBase>, // expected-error {{unknown template name 'UnknownBase'}} \ + // expected-error {{use '> >'}} + Known // expected-error {{too few template arguments for class template 'Known'}} + { }; + + template struct foo7 : + UnknownBase1)> // expected-error {{unknown template name 'UnknownBase'}} + { }; + + template struct foo8 : + UnknownBase,X> // expected-error {{unknown template name 'UnknownBase'}} \ + // expected-error {{use '> >'}} + { }; + + template struct foo9 : + UnknownBase,X> // expected-error {{unknown template name 'UnknownBase'}} \ + // expected-error {{use '> >'}} + { }; + + template struct foo10 : + UnknownBase,X>> // expected-error {{unknown template name 'UnknownBase'}} \ + // expected-error {{use '> >'}} + { }; + + template struct foo11 : + UnknownBase<2 // expected-error {{unknown template name 'UnknownBase'}} + { }; + +} diff --git a/clang/test/SemaCXX/class.cpp b/clang/test/SemaCXX/class.cpp index 972a79bb609005641669bc0a8200effd336b6d16..636f584cf625be9a85a8713d83bec80880e32cb2 100644 --- a/clang/test/SemaCXX/class.cpp +++ b/clang/test/SemaCXX/class.cpp @@ -126,12 +126,8 @@ struct S // Don't crash on this bogus code. namespace pr6629 { - // TODO: most of these errors are spurious template struct foo : - bogus > // expected-error {{unknown template name 'bogus'}} \ - // BOGUS expected-error {{expected '{' after base class list}} \ - // BOGUS expected-error {{expected ';' after struct}} \ - // BOGUS expected-error {{expected unqualified-id}} + bogus > // expected-error {{unknown template name 'bogus'}} { }; template<> struct foo { // expected-error {{undeclared identifier 'unknown'}}