From: Giovanni Bajo Date: Thu, 15 Jan 2004 01:39:58 +0000 (+0000) Subject: re PR c++/8856 (g++ accepts invalid conversion-function-id) X-Git-Tag: releases/gcc-3.4.0~966 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0d9564747f44c5d650c3dad74097c063f9a12ad3;p=thirdparty%2Fgcc.git re PR c++/8856 (g++ accepts invalid conversion-function-id) PR c++/8856 * parser.c (cp_parser_template_name): Don't try to parse a conversion-function-id, as it cannot be a template-name. (cp_parser_simple_type_specifier): Check for invalid template-ids even after a built-in type. From-SVN: r75897 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 219f316877c2..97f60f298ba9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2004-01-15 Giovanni Bajo + + PR c++/8856 + * parser.c (cp_parser_template_name): Don't try to parse a + conversion-function-id, as it cannot be a template-name. + (cp_parser_simple_type_specifier): Check for invalid template-ids + even after a built-in type. + 2004-01-14 Jan Hubicka PR c++/12850 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index db89e4520f98..31c327ad415a 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -7882,10 +7882,19 @@ cp_parser_template_id (cp_parser *parser, template-name: identifier operator-function-id - conversion-function-id A defect report has been filed about this issue. + A conversion-function-id cannot be a template name because they cannot + be part of a template-id. In fact, looking at this code: + + a.operator K() + + the conversion-function-id is "operator K", and K is a type-id. + It is impossible to call a templated conversion-function-id with an + explicit argument list, since the only allowed template parameter is + the type to which it is converting. + If TEMPLATE_KEYWORD_P is true, then we have just seen the `template' keyword, in a construction like: @@ -7922,7 +7931,10 @@ cp_parser_template_name (cp_parser* parser, identifier = cp_parser_operator_function_id (parser); /* If that didn't work, try a conversion-function-id. */ if (!cp_parser_parse_definitely (parser)) - identifier = cp_parser_conversion_function_id (parser); + { + cp_parser_error (parser, "expected template-name"); + return error_mark_node; + } } /* Look for the identifier. */ else @@ -8705,6 +8717,12 @@ cp_parser_simple_type_specifier (cp_parser* parser, cp_parser_flags flags, /* Consume the token. */ id = cp_lexer_consume_token (parser->lexer)->value; + + /* There is no valid C++ program where a non-template type is + followed by a "<". That usually indicates that the user thought + that the type was a template. */ + cp_parser_check_for_invalid_template_id (parser, type); + return identifier_p ? id : TYPE_NAME (type); }