re PR c++/29043 (Constructor for POD type with const member without member initialize...
authorFabien Chêne <fabien.chene@gmail.com>
Wed, 28 Apr 2010 00:03:21 +0000 (00:03 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 28 Apr 2010 00:03:21 +0000 (20:03 -0400)
PR c++/29043
* init.c (perform_member_init): check for uninitialized const or
reference members, including array types.

From-SVN: r158817

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/pr29043.C [new file with mode: 0644]

index 08746bae335963f4c612975b8aad473384d168d7..3935cc21241cb6f252b47e4499b14386b2c1026f 100644 (file)
@@ -1,3 +1,9 @@
+2010-04-27  Fabien Chêne  <fabien.chene@gmail.com>
+
+       PR c++/29043
+       * init.c (perform_member_init): check for uninitialized const or
+       reference members, including array types.
+
 2010-04-24  Jason Merrill  <jason@redhat.com>
 
        * tree.c (get_fns): Split out from get_first_fn.
index e1dee1d10dcb3187c809e6ee5ea28291525efb8e..57b874d5e4a415eecbf9223be3b4d8abaec3698b 100644 (file)
@@ -506,6 +506,7 @@ perform_member_init (tree member, tree init)
     {
       if (init == NULL_TREE)
        {
+         tree core_type;
          /* member traversal: note it leaves init NULL */
          if (TREE_CODE (type) == REFERENCE_TYPE)
            permerror (DECL_SOURCE_LOCATION (current_function_decl),
@@ -515,6 +516,11 @@ perform_member_init (tree member, tree init)
            permerror (DECL_SOURCE_LOCATION (current_function_decl),
                       "uninitialized member %qD with %<const%> type %qT",
                       member, type);
+
+         core_type = strip_array_types (type);
+         if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)
+             || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type))
+           diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false);
        }
       else if (TREE_CODE (init) == TREE_LIST)
        /* There was an explicit member initialization.  Do some work
index 1bd00ff9bef5e3de35a60987d7843b1f7d0c4d2d..ac3d6e63021ce7b1952dbdb1ebbbb6bec60c07a6 100644 (file)
@@ -1,3 +1,8 @@
+2010-04-27  Fabien Chêne  <fabien.chene@gmail.com>
+
+       PR c++/29043
+       * g++.dg/init/pr29043.C: New.
+
 2010-04-27  Jason Merrill  <jason@redhat.com>
 
        * g++.dg/lookup/scoped5.C: Adjust.
diff --git a/gcc/testsuite/g++.dg/init/pr29043.C b/gcc/testsuite/g++.dg/init/pr29043.C
new file mode 100644 (file)
index 0000000..6ed31b5
--- /dev/null
@@ -0,0 +1,52 @@
+// PR c++/29043
+// { dg-do compile }
+
+struct S 
+{
+  int const i; // { dg-message "should be initialized" }
+};
+
+class C
+{
+public:
+  C() {} // { dg-error "uninitialized const member" }   
+  S s;
+};
+
+struct S2
+{
+  int& ref; // { dg-message "should be initialized" }
+};
+
+class C2
+{
+public:
+  C2() {} // { dg-error "uninitialized reference member" }   
+  S2 s;
+};
+
+class C3
+{
+  C3() { }
+  struct s {
+    const int i;
+  };
+};
+
+struct S4
+{
+  int const i; // { dg-message "should be initialized" }
+};
+
+struct C4
+{
+  C4() {} // { dg-error "uninitialized const member" }
+  S4 s4[ 1 ];
+};
+
+struct C5
+{
+  C5() {} // { dg-message "uninitialized" }   
+  int const iit[ 1 ];
+};
+