Weird things are going to happen if you define your std::initializer_list
as a union. In this case, we crash in output_constructor_regular_field.
Let's not allow such a definition in the first place.
PR c++/102434
gcc/cp/ChangeLog:
* class.cc (finish_struct): Don't allow union initializer_list.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/initlist128.C: New test.
ok = true;
}
}
+ /* It also cannot be a union. */
+ ok &= NON_UNION_CLASS_TYPE_P (t);
if (!ok)
fatal_error (input_location, "definition of %qD does not match "
"%<#include <initializer_list>%>", TYPE_NAME (t));
--- /dev/null
+// PR c++/102434
+// { dg-do compile { target c++11 } }
+
+using size_t = decltype(sizeof 0);
+
+namespace std {
+ template<typename T> union initializer_list { // { dg-error "definition of .*std::initializer_list.* does not match" }
+ const T *ptr;
+ size_t n;
+ };
+}
+template<typename T>
+void Task() {}
+auto b = { &Task<int> };
+
+// { dg-prune-output "compilation terminated" }