Commit 5c67ef9a by Jason Merrill Committed by Jason Merrill

re PR c++/49988 (constexpr on ctor invokes improper initialization)

	PR c++/49988
	* semantics.c (cxx_eval_array_reference): Handle failure to
	reduce the array operand to something we can work with.

From-SVN: r177496
parent de9ef71c
2011-08-05 Jason Merrill <jason@redhat.com>
PR c++/49988
* semantics.c (cxx_eval_array_reference): Handle failure to
reduce the array operand to something we can work with.
2011-08-05 Gabriel Charette <gchare@google.com>
* decl.c (finish_function): Remove unecessary line 0 hack.
......
......@@ -6428,12 +6428,19 @@ cxx_eval_array_reference (const constexpr_call *call, tree t,
elem_type = TREE_TYPE (TREE_TYPE (ary));
if (TREE_CODE (ary) == CONSTRUCTOR)
len = CONSTRUCTOR_NELTS (ary);
else
else if (TREE_CODE (ary) == STRING_CST)
{
elem_nchars = (TYPE_PRECISION (elem_type)
/ TYPE_PRECISION (char_type_node));
len = (unsigned) TREE_STRING_LENGTH (ary) / elem_nchars;
}
else
{
/* We can't do anything with other tree codes, so use
VERIFY_CONSTANT to complain and fail. */
VERIFY_CONSTANT (ary);
gcc_unreachable ();
}
if (compare_tree_int (index, len) >= 0)
{
if (tree_int_cst_lt (index, array_type_nelts_top (TREE_TYPE (ary))))
......
2011-08-05 Jason Merrill <jason@redhat.com>
PR c++/49988
* g++.dg/cpp0x/constexpr-non-const-arg3.C: New.
2011-08-05 H.J. Lu <hongjiu.lu@intel.com>
PR target/47369
......
// PR c++/49988
// { dg-options -std=c++0x }
// { dg-do run }
template<int ... I> struct X { };
struct A {
char data[3];
template<int ... I>
constexpr
A(const char (&s)[3], X<I...> x) : data{ s[I]...} { }
};
struct B {
A a;
B(const char (&s)[3]) : a{s,X<0,1,2>{}} { }
};
int main()
{
B b{"12"};
if (b.a.data[0] != '1')
return 1;
}
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