diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 531554d702d5..b569644514c7 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -29241,7 +29241,13 @@ do_auto_deduction (tree type, tree init, tree auto_node, if (type == error_mark_node) return error_mark_node; - init = resolve_nondeduced_context (init, complain); + 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); + else + init = resolve_nondeduced_context (init, complain); if (context == adc_decomp_type && auto_node == type diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-deduce3.C b/gcc/testsuite/g++.dg/cpp0x/initlist-deduce3.C new file mode 100644 index 000000000000..b8417d7bf0c1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-deduce3.C @@ -0,0 +1,22 @@ +// PR c++/93107 +// { dg-do compile { target c++11 } } + +using size_t = decltype(sizeof 0); + +namespace std { + template struct initializer_list { + const T *ptr; + size_t n; + initializer_list(const T*, size_t); + }; +} + +template +void Task() {} + +auto a = &Task; +auto b = { &Task }; +auto e{ &Task }; +auto f = { &Task, &Task }; +std::initializer_list c = { &Task }; +auto d = { static_cast(&Task) };