diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index bbc7dadde8f3..9719d857f39e 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -1049,6 +1049,11 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression, // simple-type-specifier braced-init-list // DeclSpec DS(AttrFactory); + + if (!Actions.isSimpleTypeSpecifier(Tok.getKind())) + // This can happen if we tried to recover from errors earlier. + return ExprError(); + ParseCXXSimpleTypeSpecifier(DS); if (Tok.isNot(tok::l_paren) && (!getLangOpts().CPlusPlus11 || Tok.isNot(tok::l_brace))) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 68762e97fa2b..92400df00ce2 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -108,6 +108,7 @@ bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) const { case tok::kw_char16_t: case tok::kw_char32_t: case tok::kw_typeof: + case tok::annot_decltype: case tok::kw_decltype: return getLangOpts().CPlusPlus; diff --git a/clang/test/Parser/cxx-decl.cpp b/clang/test/Parser/cxx-decl.cpp index 281e33b20f8b..c33a8d561caf 100644 --- a/clang/test/Parser/cxx-decl.cpp +++ b/clang/test/Parser/cxx-decl.cpp @@ -209,6 +209,14 @@ namespace PR5066 { using T = int (*T)(); // expected-error {{type-id cannot have a name}} expected-warning {{C++11}} } +namespace PR17255 { +void foo() { + typename A::template B<>; // expected-error {{use of undeclared identifier 'A'}} \ + // expected-error {{expected a qualified name after 'typename'}} \ + // expected-warning {{'template' keyword outside of a template}} +} +} + // PR8380 extern "" // expected-error {{unknown linkage language}} test6a { ;// expected-error {{C++ requires a type specifier for all declarations}} \