PR c++/51633 - ICEs with constexpr constructor
authorDodji Seketeli <dodji@redhat.com>
Thu, 12 Jan 2012 23:28:46 +0000 (23:28 +0000)
committerDodji Seketeli <dodji@gcc.gnu.org>
Thu, 12 Jan 2012 23:28:46 +0000 (00:28 +0100)
gcc/cp/

PR c++/51633
* semantics.c (cp_parser_ctor_initializer_opt_and_function_body):
Set the pointer to the last block of the constructor to the
current statement.
(build_constexpr_constructor_member_initializers): Get
build_data_member_initialization a chance to deal with more
statements before we choke.

gcc/testsuite/

PR c++/51633
* g++.dg/cpp0x/constexpr-diag4.C: New test.

From-SVN: r183144

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

index 6047df3a2ed0ad625d0b771abab74f8beb30cb07..63d8f2f4d1aedc0f444797ae9ca075c67af9166f 100644 (file)
@@ -1,3 +1,13 @@
+2012-01-13  Dodji Seketeli  <dodji@redhat.com>
+
+       PR c++/51633
+       * semantics.c (cp_parser_ctor_initializer_opt_and_function_body):
+       Set the pointer to the last block of the constructor to the
+       current statement.
+       (build_constexpr_constructor_member_initializers): Get
+       build_data_member_initialization a chance to deal with more
+       statements before we choke.
+
 2012-01-12  Jason Merrill  <jason@redhat.com>
 
        PR c++/48051
index 4c853552f4f4e67d2dea621e9d4b72d953b73540..c4c3ef44a0ced950139a9794fc5ab0a34de0c9fd 100644 (file)
@@ -17424,11 +17424,8 @@ cp_parser_ctor_initializer_opt_and_function_body (cp_parser *parser)
      cp_parser_function_body changed its state.  */
   if (check_body_p)
     {
-      list = body;
-      if (TREE_CODE (list) == BIND_EXPR)
-       list = BIND_EXPR_BODY (list);
-      if (TREE_CODE (list) == STATEMENT_LIST
-         && STATEMENT_LIST_TAIL (list) != NULL)
+      list = cur_stmt_list;
+      if (STATEMENT_LIST_TAIL (list))
        last = STATEMENT_LIST_TAIL (list)->stmt;
     }
   /* Parse the function-body.  */
index 2c351bee020151148f83851c3b504a5972e19f56..6f6f0aca4b10b291ada14760f3241d07be5a6315 100644 (file)
@@ -5930,6 +5930,8 @@ build_constexpr_constructor_member_initializers (tree type, tree body)
            break;
        }
     }
+  else if (EXPR_P (body))
+    ok = build_data_member_initialization (body, &vec);
   else
     gcc_assert (errorcount > 0);
   if (ok)
index 224f98f0e709a782cdbe64c806b6d1511c69722d..a4b09ea66027017134498107e37bf8166468d7e2 100644 (file)
@@ -1,3 +1,8 @@
+2012-01-13  Dodji Seketeli  <dodji@redhat.com>
+
+       PR c++/51633
+       * g++.dg/cpp0x/constexpr-diag4.C: New test.
+
 2012-01-12  Jason Merrill  <jason@redhat.com>
 
        PR c++/48051
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-diag4.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-diag4.C
new file mode 100644 (file)
index 0000000..371190e
--- /dev/null
@@ -0,0 +1,25 @@
+// Origin: PR c++/51633
+// { dg-options "-std=c++11" }
+
+struct A
+{
+    ~A();
+};
+
+struct B
+{
+    A a;
+    constexpr B() {}
+};
+
+struct A1
+{
+    int a;
+    ~A1();
+};
+
+struct B1
+{
+    A1 a1;
+    constexpr B1() {} // { dg-error "uninitialized member" }
+};
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-diag5.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-diag5.C
new file mode 100644 (file)
index 0000000..c0cbfdd
--- /dev/null
@@ -0,0 +1,48 @@
+// Origin: PR c++/51633
+// { dg-options "-std=c++11" }
+
+struct A
+{
+    constexpr A() {}
+    ~A();
+};
+
+struct B
+{
+    A a;
+    A b;
+    A c;
+    constexpr B() {}
+};
+
+struct C
+{
+    A a;
+    constexpr C() {}
+};
+
+struct D
+{
+    constexpr D() { return;} // { dg-error "does not have empty body" }
+};
+
+struct D1
+{
+    A a;
+    constexpr D1() { return;} // { dg-error "does not have empty body" }
+};
+
+struct D2
+{
+    A a;
+    A b;
+    constexpr D2() { return;} // { dg-error "does not have empty body" }
+};
+
+struct D3
+{
+    A a;
+    A b;
+    A c;
+    constexpr D3() { return;} // { dg-error "does not have empty body" }
+};