aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorGiovanni Bajo <giovannibajo@gcc.gnu.org>2004-01-15 01:39:58 +0000
committerGiovanni Bajo <giovannibajo@gcc.gnu.org>2004-01-15 01:39:58 +0000
commit0d9564747f44c5d650c3dad74097c063f9a12ad3 (patch)
treeea278fe76b46ba3f98ccb5652e3cfb5a9713bd49 /gcc
parent38bdcc805a4d2d85df84faa09b466ecff7cb832b (diff)
downloadgcc-0d9564747f44c5d650c3dad74097c063f9a12ad3.zip
gcc-0d9564747f44c5d650c3dad74097c063f9a12ad3.tar.gz
gcc-0d9564747f44c5d650c3dad74097c063f9a12ad3.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/parser.c22
2 files changed, 28 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 219f316..97f60f2 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+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>
PR c++/12850
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index db89e45..31c327a 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<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
`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);
}