mirror of git://gcc.gnu.org/git/gcc.git
re PR c++/49924 ([C++0X] [constexpr] can't initialize a non-static member array of a literal type as a constexpr)
PR c++/49924 * semantics.c (cxx_eval_vec_init_1): Fix logic. From-SVN: r177073
This commit is contained in:
parent
172c08a544
commit
3748a54ca3
|
|
@ -1,5 +1,8 @@
|
||||||
2011-08-01 Jason Merrill <jason@redhat.com>
|
2011-08-01 Jason Merrill <jason@redhat.com>
|
||||||
|
|
||||||
|
PR c++/49924
|
||||||
|
* semantics.c (cxx_eval_vec_init_1): Fix logic.
|
||||||
|
|
||||||
PR c++/49813
|
PR c++/49813
|
||||||
* semantics.c (potential_constant_expression_1): Allow any builtin.
|
* semantics.c (potential_constant_expression_1): Allow any builtin.
|
||||||
(morally_constexpr_builtin_function_p): Remove.
|
(morally_constexpr_builtin_function_p): Remove.
|
||||||
|
|
|
||||||
|
|
@ -6651,6 +6651,7 @@ cxx_eval_vec_init_1 (const constexpr_call *call, tree atype, tree init,
|
||||||
tree elttype = TREE_TYPE (atype);
|
tree elttype = TREE_TYPE (atype);
|
||||||
int max = tree_low_cst (array_type_nelts (atype), 0);
|
int max = tree_low_cst (array_type_nelts (atype), 0);
|
||||||
VEC(constructor_elt,gc) *n = VEC_alloc (constructor_elt, gc, max + 1);
|
VEC(constructor_elt,gc) *n = VEC_alloc (constructor_elt, gc, max + 1);
|
||||||
|
bool pre_init = false;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* For the default constructor, build up a call to the default
|
/* For the default constructor, build up a call to the default
|
||||||
|
|
@ -6658,8 +6659,15 @@ cxx_eval_vec_init_1 (const constexpr_call *call, tree atype, tree init,
|
||||||
here, as for a constructor to be constexpr, all members must be
|
here, as for a constructor to be constexpr, all members must be
|
||||||
initialized, which for a defaulted default constructor means they must
|
initialized, which for a defaulted default constructor means they must
|
||||||
be of a class type with a constexpr default constructor. */
|
be of a class type with a constexpr default constructor. */
|
||||||
if (value_init)
|
if (TREE_CODE (elttype) == ARRAY_TYPE)
|
||||||
gcc_assert (!init);
|
/* We only do this at the lowest level. */;
|
||||||
|
else if (value_init)
|
||||||
|
{
|
||||||
|
init = build_value_init (elttype, tf_warning_or_error);
|
||||||
|
init = cxx_eval_constant_expression
|
||||||
|
(call, init, allow_non_constant, addr, non_constant_p);
|
||||||
|
pre_init = true;
|
||||||
|
}
|
||||||
else if (!init)
|
else if (!init)
|
||||||
{
|
{
|
||||||
VEC(tree,gc) *argvec = make_tree_vector ();
|
VEC(tree,gc) *argvec = make_tree_vector ();
|
||||||
|
|
@ -6669,6 +6677,7 @@ cxx_eval_vec_init_1 (const constexpr_call *call, tree atype, tree init,
|
||||||
release_tree_vector (argvec);
|
release_tree_vector (argvec);
|
||||||
init = cxx_eval_constant_expression (call, init, allow_non_constant,
|
init = cxx_eval_constant_expression (call, init, allow_non_constant,
|
||||||
addr, non_constant_p);
|
addr, non_constant_p);
|
||||||
|
pre_init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*non_constant_p && !allow_non_constant)
|
if (*non_constant_p && !allow_non_constant)
|
||||||
|
|
@ -6690,17 +6699,14 @@ cxx_eval_vec_init_1 (const constexpr_call *call, tree atype, tree init,
|
||||||
allow_non_constant, addr,
|
allow_non_constant, addr,
|
||||||
non_constant_p);
|
non_constant_p);
|
||||||
}
|
}
|
||||||
else if (value_init)
|
else if (pre_init)
|
||||||
{
|
{
|
||||||
eltinit = build_value_init (elttype, tf_warning_or_error);
|
/* Initializing an element using value or default initialization
|
||||||
eltinit = cxx_eval_constant_expression
|
we just pre-built above. */
|
||||||
(call, eltinit, allow_non_constant, addr, non_constant_p);
|
if (i == 0)
|
||||||
}
|
eltinit = init;
|
||||||
else if (TREE_CODE (init) == CONSTRUCTOR)
|
else
|
||||||
{
|
eltinit = unshare_expr (init);
|
||||||
/* Initializing an element using the call to the default
|
|
||||||
constructor we just built above. */
|
|
||||||
eltinit = unshare_expr (init);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
2011-08-01 Jason Merrill <jason@redhat.com>
|
2011-08-01 Jason Merrill <jason@redhat.com>
|
||||||
|
|
||||||
|
PR c++/49924
|
||||||
|
* g++.dg/cpp0x/constexpr-array4.C: New.
|
||||||
|
|
||||||
PR c++/49813
|
PR c++/49813
|
||||||
* g++.dg/cpp0x/constexpr-builtin1.C: New.
|
* g++.dg/cpp0x/constexpr-builtin1.C: New.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
// PR c++/49924
|
||||||
|
// { dg-options -std=c++0x }
|
||||||
|
|
||||||
|
struct A { constexpr A() { } };
|
||||||
|
|
||||||
|
struct B {
|
||||||
|
A array[1]; //non-static member array of a literal type w constexpr ctor
|
||||||
|
constexpr B() : array{} { } // here is the problem
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
constexpr B b{}; // won't compile
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue