Hi,

this remained unresolved for a long time, but, if I understand correctly Jason' Comment 1, should be rather easy, just do not complain for uninitialized const members in aggregates, recursively too (per struct B in the testcases). Does the below makes sense, then?!? It passes testing, anyway. I'm also taking the occasion to guard the warnings with complain & tf_warning.

Thanks,
Paolo.

/////////////////////
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c        (revision 211955)
+++ cp/typeck2.c        (working copy)
@@ -1342,28 +1342,15 @@ process_init_constructor_record (tree type, tree i
          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 (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
            {
              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 (complain & tf_error)
                error ("member %qD is uninitialized reference", field);
              else
                return PICFLAG_ERRONEOUS;
@@ -1371,8 +1358,9 @@ process_init_constructor_record (tree type, tree i
 
          /* 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,
Index: testsuite/g++.dg/cpp0x/aggr1.C
===================================================================
--- testsuite/g++.dg/cpp0x/aggr1.C      (revision 0)
+++ testsuite/g++.dg/cpp0x/aggr1.C      (working copy)
@@ -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{};
Index: testsuite/g++.dg/init/aggr11.C
===================================================================
--- testsuite/g++.dg/init/aggr11.C      (revision 0)
+++ testsuite/g++.dg/init/aggr11.C      (working copy)
@@ -0,0 +1,13 @@
+// PR c++/49132
+
+struct A {
+  const int m;
+};
+
+A a1 = {};
+
+struct B {
+  A a;
+};
+
+B b1 = {};

Reply via email to