re PR c++/65973 (segmentation fault when compiling C++14 code)
authorJason Merrill <jason@redhat.com>
Fri, 19 Jun 2015 18:15:30 +0000 (14:15 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 19 Jun 2015 18:15:30 +0000 (14:15 -0400)
PR c++/65973
* constexpr.c (build_constexpr_constructor_member_initializers):
Handle an empty STATEMENT_LIST.

From-SVN: r224677

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

index 4f2d4a6e27bbea36a7f2475a40a3ee0f696b737c..2f5e0fa8c125d50b195aa749b2f6a511b6aba3f7 100644 (file)
@@ -1,5 +1,9 @@
 2015-06-19  Jason Merrill  <jason@redhat.com>
 
+       PR c++/65973
+       * constexpr.c (build_constexpr_constructor_member_initializers):
+       Handle an empty STATEMENT_LIST.
+
        PR c++/65843
        * pt.c (tsubst_copy_and_build): Register a capture proxy in
        local_specializations.
index 56885883d72aa090f45ceed274fc29bfd55e7dfa..f6e2bc8508c08b4c7e38a60f9398b3df1ee4c9b6 100644 (file)
@@ -537,16 +537,16 @@ build_constexpr_constructor_member_initializers (tree type, tree body)
     body = TREE_OPERAND (body, 0);
   if (TREE_CODE (body) == STATEMENT_LIST)
     {
-      tree_stmt_iterator i = tsi_start (body);
-      while (true)
+      for (tree_stmt_iterator i = tsi_start (body);
+          !tsi_end_p (i); tsi_next (&i))
        {
          body = tsi_stmt (i);
          if (TREE_CODE (body) == BIND_EXPR)
            break;
-         tsi_next (&i);
        }
     }
-  body = BIND_EXPR_BODY (body);
+  if (TREE_CODE (body) == BIND_EXPR)
+    body = BIND_EXPR_BODY (body);
   if (TREE_CODE (body) == CLEANUP_POINT_EXPR)
     {
       body = TREE_OPERAND (body, 0);
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-empty1.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-empty1.C
new file mode 100644 (file)
index 0000000..5be44ea
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/65973
+// { dg-do compile { target c++14 } }
+
+class foo {
+  constexpr foo() noexcept { __func__; };
+};