From: Volker Reichelt Date: Thu, 1 Sep 2005 15:23:21 +0000 (+0000) Subject: Backport: X-Git-Tag: releases/gcc-3.4.5~221 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=792e226efadefd93ac6b26868136686075af611e;p=thirdparty%2Fgcc.git Backport: 2004-11-27 Mark Mitchell PR c++/18512 * parser.c (cp_parser_postfix_expression): Robustify. * g++.dg/template/crash29.C: New test. From-SVN: r103734 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b485511eaf4c..20484b9b84e6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2005-09-01 Volker Reichelt + + Backport: + + 2004-11-27 Mark Mitchell + PR c++/18512 + * parser.c (cp_parser_postfix_expression): Robustify. + 2005-09-01 Volker Reichelt Backport: diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 1edbafca7ccd..1ae93effd64b 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -3966,20 +3966,29 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p) if (parser->scope) idk = CP_ID_KIND_QUALIFIED; - if (name != error_mark_node - && !BASELINK_P (name) - && parser->scope) + /* If the name is a template-id that names a type, we will + get a TYPE_DECL here. That is invalid code. */ + if (TREE_CODE (name) == TYPE_DECL) { - name = build_nt (SCOPE_REF, parser->scope, name); - parser->scope = NULL_TREE; - parser->qualifying_scope = NULL_TREE; - parser->object_scope = NULL_TREE; + error ("invalid use of `%D'", name); + postfix_expression = error_mark_node; + } + else + { + if (name != error_mark_node && !BASELINK_P (name) + && parser->scope) + { + name = build_nt (SCOPE_REF, parser->scope, name); + parser->scope = NULL_TREE; + parser->qualifying_scope = NULL_TREE; + parser->object_scope = NULL_TREE; + } + if (scope && name && BASELINK_P (name)) + adjust_result_of_qualified_name_lookup + (name, BINFO_TYPE (BASELINK_BINFO (name)), scope); + postfix_expression = finish_class_member_access_expr + (postfix_expression, name); } - if (scope && name && BASELINK_P (name)) - adjust_result_of_qualified_name_lookup - (name, BINFO_TYPE (BASELINK_BINFO (name)), scope); - postfix_expression - = finish_class_member_access_expr (postfix_expression, name); } /* We no longer need to look up names in the scope of the diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0bd2505f7734..f77f19704665 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2005-09-01 Volker Reichelt + + Backport: + + 2004-11-27 Mark Mitchell + PR c++/18512 + * g++.dg/template/crash29.C: New test. + 2005-09-01 Volker Reichelt Backport: diff --git a/gcc/testsuite/g++.dg/template/crash29.C b/gcc/testsuite/g++.dg/template/crash29.C index 55953ed80100..681d2ce38d6b 100644 --- a/gcc/testsuite/g++.dg/template/crash29.C +++ b/gcc/testsuite/g++.dg/template/crash29.C @@ -4,5 +4,5 @@ template struct A {}; struct B : A<0> { - void foo() { this->A<0>; } // { dg-error "" } + void foo() { this->A<0>; } // { dg-error "invalid use" } };