Unfortunately, the otherwise beautiful
for (constructor_elt &elt : *CONSTRUCTOR_ELTS (init))
is not immune to an empty constructor, so we have to check
CONSTRUCTOR_ELTS first.
gcc/cp/ChangeLog:
PR c++/97895
* pt.c (do_auto_deduction): Don't crash when the constructor has
zero elements.
gcc/testsuite/ChangeLog:
PR c++/97895
* g++.dg/cpp0x/auto54.C: New test.
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);
--- /dev/null
+// PR c++/97895
+// { dg-do compile { target c++11 } }
+
+namespace std {
+ template<typename T> struct initializer_list {
+ const T *ptr;
+ decltype(sizeof 0) n;
+ };
+ auto a = {}; // { dg-error "unable to deduce" }
+}