+2014-07-15 Jason Merrill <jason@redhat.com>
+
+ PR c++/60848
+ PR c++/61723
+ * call.c (is_std_init_list): Don't check CLASSTYPE_TEMPLATE_INFO.
+ * class.c (finish_struct): Reject invalid definition of
+ std::initializer_list.
+
2014-07-15 Paolo Carlini <paolo.carlini@oracle.com>
* call.c (convert_like_real): Call print_z_candidate and inform only
type = TYPE_MAIN_VARIANT (type);
return (CLASS_TYPE_P (type)
&& CP_TYPE_CONTEXT (type) == std_node
- && CLASSTYPE_TEMPLATE_INFO (type)
&& strcmp (TYPE_NAME_STRING (type), "initializer_list") == 0);
}
else
finish_struct_1 (t);
+ if (is_std_init_list (t))
+ {
+ /* People keep complaining that the compiler crashes on an invalid
+ definition of initializer_list, so I guess we should explicitly
+ reject it. What the compiler internals care about is that it's a
+ template and has a pointer field followed by an integer field. */
+ bool ok = false;
+ if (processing_template_decl)
+ {
+ tree f = next_initializable_field (TYPE_FIELDS (t));
+ if (f && TREE_CODE (TREE_TYPE (f)) == POINTER_TYPE)
+ {
+ f = next_initializable_field (DECL_CHAIN (f));
+ if (f && TREE_CODE (TREE_TYPE (f)) == INTEGER_TYPE)
+ ok = true;
+ }
+ }
+ if (!ok)
+ fatal_error ("definition of std::initializer_list does not match "
+ "#include <initializer_list>");
+ }
+
input_location = saved_loc;
TYPE_BEING_DEFINED (t) = 0;
namespace std
{
- struct initializer_list {};
+ struct initializer_list {}; // { dg-message "initializer_list" }
}
void foo(std::initializer_list &);
void f()
{
- foo({1, 2}); // { dg-error "" }
+ foo({1, 2});
}
+
+// { dg-prune-output "compilation terminated" }
--- /dev/null
+// PR c++/61723
+// { dg-do compile { target c++11 } }
+
+namespace std {
+ template < class > struct initializer_list // { dg-message "initializer_list" }
+ {
+#if BUG1
+ int _M_len;
+#endif
+ const int *begin ();
+ const int *end ();
+ };
+}
+
+struct J
+{
+ J (const int &);
+ template < typename InputIterator > J (InputIterator, InputIterator);
+ J (std::initializer_list < int >p1):J (p1.begin (), p1.end ()) { }
+};
+
+struct L
+{
+ L ():dim (0) { }
+ J dim;
+};
+
+void
+fn1 ()
+{
+ L spec;
+ spec.dim = { };
+}
+
+// { dg-prune-output "compilation terminated" }