From e7db86ddb01ce22de3923822cfcc98bdc48b494e Mon Sep 17 00:00:00 2001 From: John McCall Date: Fri, 30 Apr 2010 03:11:01 +0000 Subject: [PATCH] Fix a tentative-parse error with unqualified template ids in cast expressions. Also resolve a long-working FIXME in the test case I modified. llvm-svn: 102688 --- clang/lib/Parse/ParseTentative.cpp | 13 +++++++++++++ clang/test/Parser/cxx-casting.cpp | 9 ++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp index 516a9a620b62..a6c6d3f94535 100644 --- a/clang/lib/Parse/ParseTentative.cpp +++ b/clang/lib/Parse/ParseTentative.cpp @@ -14,6 +14,7 @@ #include "clang/Parse/Parser.h" #include "clang/Parse/ParseDiagnostic.h" +#include "clang/Parse/Template.h" using namespace clang; /// isCXXDeclarationStatement - C++-specialized function that disambiguates @@ -761,6 +762,17 @@ Parser::TPResult Parser::isCXXDeclarationSpecifier() { case tok::kw___vector: return TPResult::True(); + case tok::annot_template_id: { + TemplateIdAnnotation *TemplateId + = static_cast(Tok.getAnnotationValue()); + if (TemplateId->Kind != TNK_Type_template) + return TPResult::False(); + CXXScopeSpec SS; + AnnotateTemplateIdTokenAsType(&SS); + assert(Tok.is(tok::annot_typename)); + goto case_typename; + } + case tok::annot_cxxscope: // foo::bar or ::foo::bar, but already parsed // We've already annotated a scope; try to annotate a type. if (TryAnnotateTypeOrScopeToken()) @@ -801,6 +813,7 @@ Parser::TPResult Parser::isCXXDeclarationSpecifier() { case tok::kw_double: case tok::kw_void: case tok::annot_typename: + case_typename: if (NextToken().is(tok::l_paren)) return TPResult::Ambiguous(); diff --git a/clang/test/Parser/cxx-casting.cpp b/clang/test/Parser/cxx-casting.cpp index c8b4716aa356..98d962ad0998 100644 --- a/clang/test/Parser/cxx-casting.cpp +++ b/clang/test/Parser/cxx-casting.cpp @@ -5,8 +5,6 @@ char *const_cast_test(const char *var) return const_cast(var); } -#if 0 -// FIXME: Uncomment when C++ is supported more. struct A { virtual ~A() {} }; @@ -18,7 +16,6 @@ struct B *dynamic_cast_test(struct A *a) { return dynamic_cast(a); } -#endif char *reinterpret_cast_test() { @@ -34,3 +31,9 @@ char postfix_expr_test() { return reinterpret_cast(0xdeadbeef)[0]; } + +// This was being incorrectly tentatively parsed. +namespace test1 { + template class A {}; + void foo() { A(*(A*)0); } +} -- GitLab