aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2012-10-23 23:43:21 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2012-10-23 23:43:21 +0000
commit7c7e8c7809deedd7777aafc91c763eaad99db166 (patch)
treeeeaa77dee41204f98682a892a92f5941c486cfd7 /gcc
parent0d6414b24c4041d9a5f7ceaf382d189230702084 (diff)
downloadgcc-7c7e8c7809deedd7777aafc91c763eaad99db166.zip
gcc-7c7e8c7809deedd7777aafc91c763eaad99db166.tar.gz
gcc-7c7e8c7809deedd7777aafc91c763eaad99db166.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/semantics.c12
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-union4.C13
4 files changed, 34 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1cad796..9e8d933 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 6798c1b..63b364c 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 b9bee3f..19556ce 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
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 0000000..5695cb2
--- /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() {}
+};