]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/54922 ([C++11][DR 1359] constexpr constructors require initialization of...
authorPaolo Carlini <paolo.carlini@oracle.com>
Tue, 23 Oct 2012 23:43:21 +0000 (23:43 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 23 Oct 2012 23:43:21 +0000 (23:43 +0000)
/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

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-union4.C [new file with mode: 0644]

index 1cad7963182f4901ac7d61fc5bab6302786d3cff..9e8d933e7459bfde355d53164d080eb0eff31a62 100644 (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
index 6798c1bf5d4d1ce95348c97ad560bbd5879eba96..63b364c37de6cf78f919b1e09104499ee7188f5f 100644 (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
index b9bee3f32e490ab53af60ba9166725620ffe3269..19556ce21615becfa04f299da163e96a02527734 100644 (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
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-union4.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-union4.C
new file mode 100644 (file)
index 0000000..5695cb2
--- /dev/null
@@ -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() {}
+};