diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 1babf833d321..a1b6631d6915 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -29250,10 +29250,13 @@ do_auto_deduction (tree type, tree init, tree auto_node, return error_mark_node; if (BRACE_ENCLOSED_INITIALIZER_P (init)) - /* We don't recurse here because we can't deduce from a nested - initializer_list. */ - for (constructor_elt &elt : *CONSTRUCTOR_ELTS (init)) - elt.value = resolve_nondeduced_context (elt.value, complain); + { + /* We don't recurse here because we can't deduce from a nested + initializer_list. */ + if (CONSTRUCTOR_ELTS (init)) + for (constructor_elt &elt : *CONSTRUCTOR_ELTS (init)) + elt.value = resolve_nondeduced_context (elt.value, complain); + } else init = resolve_nondeduced_context (init, complain); diff --git a/gcc/testsuite/g++.dg/cpp0x/auto54.C b/gcc/testsuite/g++.dg/cpp0x/auto54.C new file mode 100644 index 000000000000..0c1815a99bce --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/auto54.C @@ -0,0 +1,10 @@ +// PR c++/97895 +// { dg-do compile { target c++11 } } + +namespace std { + template struct initializer_list { + const T *ptr; + decltype(sizeof 0) n; + }; + auto a = {}; // { dg-error "unable to deduce" } +}