Commit 0090caca by Jason Merrill Committed by Jason Merrill

re PR c++/60848 (Crash while experimenting with c++-0x initializer lists)

	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.

From-SVN: r212574
parent e27989c4
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
......
......@@ -9701,7 +9701,6 @@ is_std_init_list (tree type)
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);
}
......
......@@ -6695,6 +6695,28 @@ finish_struct (tree t, tree attributes)
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;
......
......@@ -3,12 +3,14 @@
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" }
// 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" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment