Commit 0d956474 by Giovanni Bajo

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
parent 38bdcc80
2004-01-15 Giovanni Bajo <giovannibajo@gcc.gnu.org>
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 <jh@suse.cz> 2004-01-14 Jan Hubicka <jh@suse.cz>
PR c++/12850 PR c++/12850
......
...@@ -7882,10 +7882,19 @@ cp_parser_template_id (cp_parser *parser, ...@@ -7882,10 +7882,19 @@ cp_parser_template_id (cp_parser *parser,
template-name: template-name:
identifier identifier
operator-function-id operator-function-id
conversion-function-id
A defect report has been filed about this issue. 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<int>()
the conversion-function-id is "operator K<int>", and K<int> 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 If TEMPLATE_KEYWORD_P is true, then we have just seen the
`template' keyword, in a construction like: `template' keyword, in a construction like:
...@@ -7922,7 +7931,10 @@ cp_parser_template_name (cp_parser* parser, ...@@ -7922,7 +7931,10 @@ cp_parser_template_name (cp_parser* parser,
identifier = cp_parser_operator_function_id (parser); identifier = cp_parser_operator_function_id (parser);
/* If that didn't work, try a conversion-function-id. */ /* If that didn't work, try a conversion-function-id. */
if (!cp_parser_parse_definitely (parser)) 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. */ /* Look for the identifier. */
else else
...@@ -8705,6 +8717,12 @@ cp_parser_simple_type_specifier (cp_parser* parser, cp_parser_flags flags, ...@@ -8705,6 +8717,12 @@ cp_parser_simple_type_specifier (cp_parser* parser, cp_parser_flags flags,
/* Consume the token. */ /* Consume the token. */
id = cp_lexer_consume_token (parser->lexer)->value; 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); return identifier_p ? id : TYPE_NAME (type);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment