Commit 7b37a0c5 by Jason Merrill Committed by Jason Merrill

init.c (build_value_init): Decide whether or not to zero-initialize based on…

init.c (build_value_init): Decide whether or not to zero-initialize based on user-providedness of default...

	* init.c (build_value_init): Decide whether or not to zero-initialize
	based on user-providedness of default ctor, not any ctor.
	(build_value_init_noctor): Adjust assert.

From-SVN: r175640
parent 2061820e
2011-06-29 Jason Merrill <jason@redhat.com> 2011-06-29 Jason Merrill <jason@redhat.com>
* init.c (build_value_init): Decide whether or not to zero-initialize
based on user-providedness of default ctor, not any ctor.
(build_value_init_noctor): Adjust assert.
DR 990 DR 990
* call.c (convert_like_real) [ck_user]: Handle value-initialization. * call.c (convert_like_real) [ck_user]: Handle value-initialization.
(build_new_method_call_1): Likewise. (build_new_method_call_1): Likewise.
......
...@@ -334,14 +334,20 @@ build_value_init (tree type, tsubst_flags_t complain) ...@@ -334,14 +334,20 @@ build_value_init (tree type, tsubst_flags_t complain)
if (CLASS_TYPE_P (type)) if (CLASS_TYPE_P (type))
{ {
if (type_has_user_provided_constructor (type)) /* Instead of the above, only consider the user-providedness of the
default constructor itself so value-initializing a class with an
explicitly defaulted default constructor and another user-provided
constructor works properly (c++std-core-19883). */
if (type_has_user_provided_default_constructor (type)
|| (!TYPE_HAS_DEFAULT_CONSTRUCTOR (type)
&& type_has_user_provided_constructor (type)))
return build_aggr_init_expr return build_aggr_init_expr
(type, (type,
build_special_member_call (NULL_TREE, complete_ctor_identifier, build_special_member_call (NULL_TREE, complete_ctor_identifier,
NULL, type, LOOKUP_NORMAL, NULL, type, LOOKUP_NORMAL,
complain), complain),
complain); complain);
else if (type_build_ctor_call (type)) else if (TYPE_HAS_COMPLEX_DFLT (type))
{ {
/* This is a class that needs constructing, but doesn't have /* This is a class that needs constructing, but doesn't have
a user-provided constructor. So we need to zero-initialize a user-provided constructor. So we need to zero-initialize
...@@ -371,7 +377,7 @@ build_value_init_noctor (tree type, tsubst_flags_t complain) ...@@ -371,7 +377,7 @@ build_value_init_noctor (tree type, tsubst_flags_t complain)
SFINAE-enabled. */ SFINAE-enabled. */
if (CLASS_TYPE_P (type)) if (CLASS_TYPE_P (type))
{ {
gcc_assert (!type_build_ctor_call (type)); gcc_assert (!TYPE_HAS_COMPLEX_DFLT (type));
if (TREE_CODE (type) != UNION_TYPE) if (TREE_CODE (type) != UNION_TYPE)
{ {
......
2011-06-29 Jason Merrill <jason@redhat.com> 2011-06-29 Jason Merrill <jason@redhat.com>
* g++.dg/cpp0x/initlist-value2.C: New.
* g++.dg/cpp0x/constexpr-initlist4.C: New. * g++.dg/cpp0x/constexpr-initlist4.C: New.
* g++.dg/cpp0x/initlist-value.C: New. * g++.dg/cpp0x/initlist-value.C: New.
......
// Test that we properly value-initialize a class with a user-provided
// constructor but defaulted default constructor. The FDIS got this
// wrong; see c++std-core-19883.
// { dg-options -std=c++0x }
// { dg-do run }
struct A
{
int i;
A() = default;
A(int);
};
int main()
{
A a{};
if (a.i != 0)
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