This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/65973 (ICE with vacuous constexpr ctor)


We need to deal with the case of an empty STATEMENT_LIST.

Tested x86_64-pc-linux-gnu, applying to trunk and 5.
commit 8d83ff350b98c5bce1ed99db7e9fcdd3aa818f08
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jun 19 10:48:32 2015 -0400

    	PR c++/65973
    	* constexpr.c (build_constexpr_constructor_member_initializers):
    	Handle an empty STATEMENT_LIST.

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index f6f1d6d..3c0fa77 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -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
index 0000000..5be44ea
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-empty1.C
@@ -0,0 +1,6 @@
+// PR c++/65973
+// { dg-do compile { target c++14 } }
+
+class foo {
+  constexpr foo() noexcept { __func__; };
+};

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]