re PR c++/38256 (ICE with "operator auto")

PR c++/38256
        * parser.c (cp_parser_conversion_type_id): Diagnose
        'operator auto' here.
        * decl.c (grokdeclarator): Not here.

From-SVN: r142410
This commit is contained in:
Jason Merrill 2008-12-03 16:42:22 -05:00 committed by Jason Merrill
parent 0e318fccb8
commit 64e12c68ef
5 changed files with 31 additions and 6 deletions

View File

@ -1,5 +1,10 @@
2008-12-03 Jason Merrill <jason@redhat.com>
PR c++/38256
* parser.c (cp_parser_conversion_type_id): Diagnose
'operator auto' here.
* decl.c (grokdeclarator): Not here.
PR c++/38380
* decl.c (grokdeclarator): Only set DECL_NONCONVERTING_P
on explicit constructors.

View File

@ -8258,12 +8258,7 @@ grokdeclarator (const cp_declarator *declarator,
{
if (type_uses_auto (type))
{
if (sfk == sfk_conversion)
{
error ("invalid use of %<auto%> in conversion operator");
return error_mark_node;
}
else if (!declarator->u.function.late_return_type)
if (!declarator->u.function.late_return_type)
{
error ("%qs function uses %<auto%> type specifier without"
" late return type", name);

View File

@ -8966,6 +8966,16 @@ cp_parser_conversion_type_id (cp_parser* parser)
/*initialized=*/0, &attributes);
if (attributes)
cplus_decl_attributes (&type_specified, attributes, /*flags=*/0);
/* Don't give this error when parsing tentatively. This happens to
work because we always parse this definitively once. */
if (! cp_parser_uncommitted_to_tentative_parse_p (parser)
&& type_uses_auto (type_specified))
{
error ("invalid use of %<auto%> in conversion operator");
return error_mark_node;
}
return type_specified;
}

View File

@ -1,5 +1,8 @@
2008-12-03 Jason Merrill <jason@redhat.com>
PR c++/38256
* g++.dg/cpp0x/auto11.C: New test.
PR c++/38380
* g++.dg/cpp0x/initlist10.C: New test.
* g++.old-deja/g++.eh/ctor1.C: Default ctor is a candidate too.

View File

@ -0,0 +1,12 @@
// PR c++/38256
// { dg-options "-std=c++0x" }
template<int> struct A
{
template<typename T> operator T();
};
void foo()
{
A<0>().operator auto(); // { dg-error "auto.*conversion" }
}