DR 178 PR c++/49132

/cp
2014-06-25  Paolo Carlini  <paolo.carlini@oracle.com>

	DR 178
	PR c++/49132
	* typeck2.c (process_init_constructor_record): Do not complain about
	uninitialized const members, because within aggregate-initialization,
	members without explicit initializers are value-initialized.

/testsuite
2014-06-25  Paolo Carlini  <paolo.carlini@oracle.com>

	DR 178
	PR c++/49132
	* g++.dg/cpp0x/aggr1.C: New.
	* g++.dg/cpp0x/aggr2.C: Likewise.
	* g++.dg/init/aggr11.C: Likewise.
	* g++.dg/init/aggr12.C: Likewise.

From-SVN: r211981
This commit is contained in:
Paolo Carlini 2014-06-25 14:27:35 +00:00
parent 1a7e871bab
commit c69c28351f
7 changed files with 91 additions and 20 deletions

View File

@ -1,3 +1,11 @@
2014-06-25 Paolo Carlini <paolo.carlini@oracle.com>
DR 178
PR c++/49132
* typeck2.c (process_init_constructor_record): Do not complain about
uninitialized const members, because within aggregate-initialization,
members without explicit initializers are value-initialized.
2014-06-25 Jakub Jelinek <jakub@redhat.com>
* semantics.c (finish_omp_clauses): Make sure
@ -6,7 +14,8 @@
2014-06-24 Jan Hubicka <hubicka@ucw.cz>
* class.c (check_methods, create_vtable_ptr, determine_key_method,
add_vcall_offset_vtbl_entries_1): Guard VINDEX checks by FUNCTION_DECL check.
add_vcall_offset_vtbl_entries_1): Guard VINDEX checks by
FUNCTION_DECL check.
* cp-tree.h (lang_decl_ns): Add ns_using and ns_users.
(DECL_NAMESPACE_USING, DECL_NAMESPACE_USERS): Use lang_decl_ns.
(DECL_NAMESPACE_ASSOCIATIONS): Use DECL_INITIAL.

View File

@ -1342,37 +1342,32 @@ process_init_constructor_record (tree type, tree init,
next = massage_init_elt (TREE_TYPE (field), next, complain);
/* Warn when some struct elements are implicitly initialized. */
warning (OPT_Wmissing_field_initializers,
"missing initializer for member %qD", field);
if (complain & tf_warning)
warning (OPT_Wmissing_field_initializers,
"missing initializer for member %qD", field);
}
else
{
if (TREE_READONLY (field))
{
if (complain & tf_error)
error ("uninitialized const member %qD", field);
else
return PICFLAG_ERRONEOUS;
}
else if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (TREE_TYPE (field)))
{
if (complain & tf_error)
error ("member %qD with uninitialized const fields", field);
else
return PICFLAG_ERRONEOUS;
}
else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
{
if (complain & tf_error)
error ("member %qD is uninitialized reference", field);
else
return PICFLAG_ERRONEOUS;
}
else if (CLASSTYPE_REF_FIELDS_NEED_INIT (TREE_TYPE (field)))
{
if (complain & tf_error)
error ("member %qD with uninitialized reference fields", field);
else
return PICFLAG_ERRONEOUS;
}
/* Warn when some struct elements are implicitly initialized
to zero. */
warning (OPT_Wmissing_field_initializers,
"missing initializer for member %qD", field);
if (complain & tf_warning)
warning (OPT_Wmissing_field_initializers,
"missing initializer for member %qD", field);
if (!zero_init_p (TREE_TYPE (field)))
next = build_zero_init (TREE_TYPE (field), /*nelts=*/NULL_TREE,

View File

@ -1,3 +1,12 @@
2014-06-25 Paolo Carlini <paolo.carlini@oracle.com>
DR 178
PR c++/49132
* g++.dg/cpp0x/aggr1.C: New.
* g++.dg/cpp0x/aggr2.C: Likewise.
* g++.dg/init/aggr11.C: Likewise.
* g++.dg/init/aggr12.C: Likewise.
2014-06-25 Martin Jambor <mjambor@suse.cz>
* g++.dg/ipa/pr61540.C: Remove dumping test.

View File

@ -0,0 +1,16 @@
// PR c++/49132
// { dg-do compile { target c++11 } }
struct A {
const int m;
};
A a1 = {};
A a2{};
struct B {
A a;
};
B b1 = {};
B b2{};

View File

@ -0,0 +1,16 @@
// PR c++/49132
// { dg-do compile { target c++11 } }
struct A {
int& m;
};
A a1 = {}; // { dg-error "uninitialized reference" }
A a2{}; // { dg-error "uninitialized reference" }
struct B {
A a;
};
B b1 = {}; // { dg-error "uninitialized reference" }
B b2{}; // { dg-error "uninitialized reference" }

View File

@ -0,0 +1,13 @@
// PR c++/49132
struct A {
const int m;
};
A a1 = {};
struct B {
A a;
};
B b1 = {};

View File

@ -0,0 +1,13 @@
// PR c++/49132
struct A {
int& m;
};
A a1 = {}; // { dg-error "uninitialized reference" }
struct B {
A a;
};
B b1 = {}; // { dg-error "uninitialized reference" }