From: Paolo Carlini Date: Tue, 23 Oct 2012 23:43:21 +0000 (+0000) Subject: re PR c++/54922 ([C++11][DR 1359] constexpr constructors require initialization of... X-Git-Tag: releases/gcc-4.8.0~2589 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7c7e8c7809deedd7777aafc91c763eaad99db166;p=thirdparty%2Fgcc.git re PR c++/54922 ([C++11][DR 1359] constexpr constructors require initialization of all union members) /cp 2012-10-23 Paolo Carlini PR c++/54922 * semantics.c (cx_check_missing_mem_inits): Handle anonymous union members. /testsuite 2012-10-23 Paolo Carlini PR c++/54922 * g++.dg/cpp0x/constexpr-union4.C: New. From-SVN: r192749 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1cad7963182f..9e8d933e7459 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2012-10-23 Paolo Carlini + + PR c++/54922 + * semantics.c (cx_check_missing_mem_inits): Handle anonymous union + members. + 2012-10-23 Jakub Jelinek PR c++/54844 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 6798c1bf5d4d..63b364c37de6 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6139,17 +6139,23 @@ cx_check_missing_mem_inits (tree fun, tree body, bool complain) for (i = 0; i <= nelts; ++i) { tree index; + tree anon_union_init_type = NULL_TREE; if (i == nelts) index = NULL_TREE; else { index = CONSTRUCTOR_ELT (body, i)->index; + /* Handle anonymous union members. */ + if (TREE_CODE (index) == COMPONENT_REF + && ANON_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (index, 0)))) + anon_union_init_type = TREE_TYPE (TREE_OPERAND (index, 0)); /* Skip base and vtable inits. */ - if (TREE_CODE (index) != FIELD_DECL - || DECL_ARTIFICIAL (index)) + else if (TREE_CODE (index) != FIELD_DECL + || DECL_ARTIFICIAL (index)) continue; } - for (; field != index; field = DECL_CHAIN (field)) + for (; field != index && TREE_TYPE (field) != anon_union_init_type; + field = DECL_CHAIN (field)) { tree ftype; if (TREE_CODE (field) != FIELD_DECL diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b9bee3f32e49..19556ce21615 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-10-23 Paolo Carlini + + PR c++/54922 + * g++.dg/cpp0x/constexpr-union4.C: New. + 2012-10-23 Jeff Law * gcc.c-torture/execute/pr54985.c: New test. @@ -6,7 +11,7 @@ PR debug/54508 * g++.dg/debug/dwarf2/pr54508.C: New. - + 2012-10-23 Jakub Jelinek PR c++/54844 diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-union4.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-union4.C new file mode 100644 index 000000000000..5695cb2ff7ad --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-union4.C @@ -0,0 +1,13 @@ +// PR c++/54922 +// { dg-do compile { target c++11 } } + +class nullable_int +{ + bool init_; + union { + unsigned char for_value_init; + int value_; + }; +public: + constexpr nullable_int() : init_(false), for_value_init() {} +};