From c69c28351f82d95e4c75bf40acdf7ff50c7639a0 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Wed, 25 Jun 2014 14:27:35 +0000 Subject: [PATCH] DR 178 PR c++/49132 /cp 2014-06-25 Paolo Carlini 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 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 --- gcc/cp/ChangeLog | 11 +++++++++- gcc/cp/typeck2.c | 33 +++++++++++++----------------- gcc/testsuite/ChangeLog | 9 ++++++++ gcc/testsuite/g++.dg/cpp0x/aggr1.C | 16 +++++++++++++++ gcc/testsuite/g++.dg/cpp0x/aggr2.C | 16 +++++++++++++++ gcc/testsuite/g++.dg/init/aggr11.C | 13 ++++++++++++ gcc/testsuite/g++.dg/init/aggr12.C | 13 ++++++++++++ 7 files changed, 91 insertions(+), 20 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/aggr1.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/aggr2.C create mode 100644 gcc/testsuite/g++.dg/init/aggr11.C create mode 100644 gcc/testsuite/g++.dg/init/aggr12.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 99bca4967bf..c3d520e3923 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2014-06-25 Paolo Carlini + + 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 * semantics.c (finish_omp_clauses): Make sure @@ -6,7 +14,8 @@ 2014-06-24 Jan Hubicka * 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. diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index a620f22ac5f..f57aef14316 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -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, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index aa3ceb0a92e..1370ee4bc4a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2014-06-25 Paolo Carlini + + 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 * g++.dg/ipa/pr61540.C: Remove dumping test. diff --git a/gcc/testsuite/g++.dg/cpp0x/aggr1.C b/gcc/testsuite/g++.dg/cpp0x/aggr1.C new file mode 100644 index 00000000000..0e408e6c684 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/aggr1.C @@ -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{}; diff --git a/gcc/testsuite/g++.dg/cpp0x/aggr2.C b/gcc/testsuite/g++.dg/cpp0x/aggr2.C new file mode 100644 index 00000000000..26e9dd05b62 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/aggr2.C @@ -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" } diff --git a/gcc/testsuite/g++.dg/init/aggr11.C b/gcc/testsuite/g++.dg/init/aggr11.C new file mode 100644 index 00000000000..0da3f410a5b --- /dev/null +++ b/gcc/testsuite/g++.dg/init/aggr11.C @@ -0,0 +1,13 @@ +// PR c++/49132 + +struct A { + const int m; +}; + +A a1 = {}; + +struct B { + A a; +}; + +B b1 = {}; diff --git a/gcc/testsuite/g++.dg/init/aggr12.C b/gcc/testsuite/g++.dg/init/aggr12.C new file mode 100644 index 00000000000..0c4bd3a2056 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/aggr12.C @@ -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" }