re PR c++/54922 ([C++11][DR 1359] constexpr constructors require initialization of all union members)

/cp
2012-10-23  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/54922
	* semantics.c (cx_check_missing_mem_inits): Handle anonymous union
	members.

/testsuite
2012-10-23  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/54922
	* g++.dg/cpp0x/constexpr-union4.C: New.

From-SVN: r192749
This commit is contained in:
Paolo Carlini 2012-10-23 23:43:21 +00:00 committed by Paolo Carlini
parent 0d6414b24c
commit 7c7e8c7809
4 changed files with 34 additions and 4 deletions

View File

@ -1,3 +1,9 @@
2012-10-23 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/54922
* semantics.c (cx_check_missing_mem_inits): Handle anonymous union
members.
2012-10-23 Jakub Jelinek <jakub@redhat.com>
PR c++/54844

View File

@ -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

View File

@ -1,3 +1,8 @@
2012-10-23 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/54922
* g++.dg/cpp0x/constexpr-union4.C: New.
2012-10-23 Jeff Law <law@redhat.com>
* 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 <jakub@redhat.com>
PR c++/54844

View File

@ -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() {}
};