Commit 2626fc49 by Adam Butcher Committed by Adam Butcher

re PR c++/61537 (template parameter lists wrongly detected on "struct" or…

re PR c++/61537 (template parameter lists wrongly detected on "struct" or "class" keyword on parameters)

Fix PR c++/61537

	* parser.c (cp_parser_elaborated_type_specifier): Only consider template
	parameter lists outside of function parameter scope.

	* g++.dg/template/pr61537.C: New testcase.

From-SVN: r212008
parent b9b5f433
2014-06-26 Adam Butcher <adam@jessamine.co.uk>
PR c++/61537
* parser.c (cp_parser_elaborated_type_specifier): Only consider template
parameter lists outside of function parameter scope.
2014-06-25 Paolo Carlini <paolo.carlini@oracle.com> 2014-06-25 Paolo Carlini <paolo.carlini@oracle.com>
DR 178 DR 178
......
...@@ -15081,6 +15081,18 @@ cp_parser_elaborated_type_specifier (cp_parser* parser, ...@@ -15081,6 +15081,18 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
return cp_parser_make_typename_type (parser, parser->scope, return cp_parser_make_typename_type (parser, parser->scope,
identifier, identifier,
token->location); token->location);
/* Template parameter lists apply only if we are not within a
function parameter list. */
bool template_parm_lists_apply
= parser->num_template_parameter_lists;
if (template_parm_lists_apply)
for (cp_binding_level *s = current_binding_level;
s && s->kind != sk_template_parms;
s = s->level_chain)
if (s->kind == sk_function_parms)
template_parm_lists_apply = false;
/* Look up a qualified name in the usual way. */ /* Look up a qualified name in the usual way. */
if (parser->scope) if (parser->scope)
{ {
...@@ -15123,7 +15135,7 @@ cp_parser_elaborated_type_specifier (cp_parser* parser, ...@@ -15123,7 +15135,7 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
decl = (cp_parser_maybe_treat_template_as_class decl = (cp_parser_maybe_treat_template_as_class
(decl, /*tag_name_p=*/is_friend (decl, /*tag_name_p=*/is_friend
&& parser->num_template_parameter_lists)); && template_parm_lists_apply));
if (TREE_CODE (decl) != TYPE_DECL) if (TREE_CODE (decl) != TYPE_DECL)
{ {
...@@ -15136,9 +15148,9 @@ cp_parser_elaborated_type_specifier (cp_parser* parser, ...@@ -15136,9 +15148,9 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
if (TREE_CODE (TREE_TYPE (decl)) != TYPENAME_TYPE) if (TREE_CODE (TREE_TYPE (decl)) != TYPENAME_TYPE)
{ {
bool allow_template = (parser->num_template_parameter_lists bool allow_template = (template_parm_lists_apply
|| DECL_SELF_REFERENCE_P (decl)); || DECL_SELF_REFERENCE_P (decl));
type = check_elaborated_type_specifier (tag_type, decl, type = check_elaborated_type_specifier (tag_type, decl,
allow_template); allow_template);
if (type == error_mark_node) if (type == error_mark_node)
...@@ -15224,15 +15236,16 @@ cp_parser_elaborated_type_specifier (cp_parser* parser, ...@@ -15224,15 +15236,16 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
ts = ts_global; ts = ts_global;
template_p = template_p =
(parser->num_template_parameter_lists (template_parm_lists_apply
&& (cp_parser_next_token_starts_class_definition_p (parser) && (cp_parser_next_token_starts_class_definition_p (parser)
|| cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))); || cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON)));
/* An unqualified name was used to reference this type, so /* An unqualified name was used to reference this type, so
there were no qualifying templates. */ there were no qualifying templates. */
if (!cp_parser_check_template_parameters (parser, if (template_parm_lists_apply
/*num_templates=*/0, && !cp_parser_check_template_parameters (parser,
token->location, /*num_templates=*/0,
/*declarator=*/NULL)) token->location,
/*declarator=*/NULL))
return error_mark_node; return error_mark_node;
type = xref_tag (tag_type, identifier, ts, template_p); type = xref_tag (tag_type, identifier, ts, template_p);
} }
......
2014-06-26 Adam Butcher <adam@jessamine.co.uk>
PR c++/61537
* g++.dg/template/pr61537.C: New testcase.
2014-06-25 Bill Schmidt <wschmidt@linux.vnet.ibm.com> 2014-06-25 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
* gfortran.dg/default_format_denormal_2.f90: Remove xfail for * gfortran.dg/default_format_denormal_2.f90: Remove xfail for
......
// PR c++/61537
// { dg-do compile }
struct A {};
template <typename T>
struct B
{
template <typename U>
void f(U, struct A);
};
template <typename T>
template <typename U>
void B<T>::f(U, struct A)
{
}
int main()
{
B<char> b;
b.f(42, A());
}
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