]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/38427 (crash for reference init code)
authorJakub Jelinek <jakub@redhat.com>
Thu, 18 Dec 2008 20:51:07 +0000 (21:51 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 18 Dec 2008 20:51:07 +0000 (21:51 +0100)
PR c++/38427
* init.c (perform_member_init): For value-initialized
references call permerror instead of warning and don't emit any
INIT_EXPR.

* g++.dg/init/ctor9.C: New test.

From-SVN: r142818

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

index 00415ecb92d22399b2793eca0ff7727231a39db6..0a84812fa86fa63ad8dbada3ee087a3c56ff64a6 100644 (file)
@@ -1,3 +1,10 @@
+2008-12-18  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/38427
+       * init.c (perform_member_init): For value-initialized
+       references call permerror instead of warning and don't emit any
+       INIT_EXPR.
+
 2008-12-18  Jason Merrill  <jason@redhat.com>
 
        PR c++/38485
index abcf858647346b22132bfc0c2548a58fad670154..1285f160f00fde52824f135684b5441e79e52f31 100644 (file)
@@ -435,19 +435,25 @@ perform_member_init (tree member, tree init)
     {
       /* mem() means value-initialization.  */
       if (TREE_CODE (type) == ARRAY_TYPE)
-       init = build_vec_init (decl, NULL_TREE, NULL_TREE,
-                              /*explicit_value_init_p=*/true,
-                              /* from_array=*/0,
-                              tf_warning_or_error);
+       {
+         init = build_vec_init (decl, NULL_TREE, NULL_TREE,
+                                /*explicit_value_init_p=*/true,
+                                /* from_array=*/0,
+                                tf_warning_or_error);
+         finish_expr_stmt (init);
+       }
       else
        {
          if (TREE_CODE (type) == REFERENCE_TYPE)
-           warning (0, "%Jdefault-initialization of %q#D, "
-                    "which has reference type",
-                    current_function_decl, member);
-         init = build2 (INIT_EXPR, type, decl, build_value_init (type));
+           permerror (input_location, "%Jvalue-initialization of %q#D, "
+                                      "which has reference type",
+                      current_function_decl, member);
+         else
+           {
+             init = build2 (INIT_EXPR, type, decl, build_value_init (type));
+             finish_expr_stmt (init);
+           }
        }
-      finish_expr_stmt (init);
     }
   /* Deal with this here, as we will get confused if we try to call the
      assignment op for an anonymous union.  This can happen in a
index 4756cd1792ed78f82a42d7e92bb107ca926d5f5b..0ac822cf1718d3f3c9a89de8b066033a9b5d0b06 100644 (file)
@@ -1,3 +1,8 @@
+2008-12-18  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/38427
+       * g++.dg/init/ctor9.C: New test.
+
 2008-12-18  Jason Merrill  <jason@redhat.com>
 
        PR c++/38485
diff --git a/gcc/testsuite/g++.dg/init/ctor9.C b/gcc/testsuite/g++.dg/init/ctor9.C
new file mode 100644 (file)
index 0000000..02bb570
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/38427
+// { dg-do compile }
+
+struct S
+{
+  int &ref;
+  S() : ref() {};      // { dg-error "value-initialization of" }
+};