re PR c++/84192 (ICE with statement expression)
authorMarek Polacek <polacek@redhat.com>
Fri, 16 Feb 2018 22:38:53 +0000 (22:38 +0000)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 16 Feb 2018 22:38:53 +0000 (23:38 +0100)
PR c++/84192
* constexpr.c (cxx_eval_constant_expression) <case RETURN_EXPR>: Don't
set *jump_target to anything if jump_target is NULL.

* g++.dg/cpp1y/constexpr-84192.C: New test.

Co-Authored-By: Jakub Jelinek <jakub@redhat.com>
From-SVN: r257770

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

index d4a9c67d2ec4eb67b70fa95f4fdd2876fe7889c7..728c501ad556eab4594b56b074106fca2c5335a0 100644 (file)
@@ -1,3 +1,10 @@
+2018-02-16  Marek Polacek  <polacek@redhat.com>
+           Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/84192
+       * constexpr.c (cxx_eval_constant_expression) <case RETURN_EXPR>: Don't
+       set *jump_target to anything if jump_target is NULL.
+
 2018-02-16  Jason Merrill  <jason@redhat.com>
 
        PR c++/84151 - unnecessary volatile load with static member.
index 91148aa8d72be69ec11141b80c990c1fbe416e94..bda9b2d211e3a3ec9133737e45f0c4003829beb9 100644 (file)
@@ -4254,7 +4254,16 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
        r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0),
                                          lval,
                                          non_constant_p, overflow_p);
-      *jump_target = t;
+      if (jump_target)
+       *jump_target = t;
+      else
+       {
+         /* Can happen with ({ return true; }) && false; passed to
+            maybe_constant_value.  There is nothing to jump over in this
+            case, and the bug will be diagnosed later.  */
+         gcc_assert (ctx->quiet);
+         *non_constant_p = true;
+       }
       break;
 
     case SAVE_EXPR:
index 4329ecbd76e283e482eed291405009948d11639f..79259637f213eab6727a4105b4074d8e26a68780 100644 (file)
@@ -1,3 +1,9 @@
+2018-02-16  Marek Polacek  <polacek@redhat.com>
+           Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/84192
+       * g++.dg/cpp1y/constexpr-84192.C: New test.
+
 2018-02-16  Martin Sebor  <msebor@redhat.com>
 
        PR c++/79064
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-84192.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-84192.C
new file mode 100644 (file)
index 0000000..ad9458d
--- /dev/null
@@ -0,0 +1,41 @@
+// PR c++/84192
+// { dg-do compile { target c++14 } }
+// { dg-options "" }
+
+bool
+f1 ()
+{ 
+  return ({ return true; }) && false;  // { dg-error "could not convert" }
+}
+
+void
+f2 ()
+{ 
+  for (;;)
+    constexpr bool b = ({ break; false; }) && false;   // { dg-error "statement is not a constant expression" }
+}
+
+constexpr bool
+f3 (int n)
+{
+  bool b = false;
+  for (int i = 0; i < n; i++)
+    b = ({ break; });  // { dg-error "void value not ignored as it ought to be" }
+  return b;
+}
+
+constexpr bool b = f3 (4);
+
+bool
+f4 ()
+{
+  constexpr bool b = ({ return true; }) && false;      // { dg-error "could not convert" }
+  return false;
+}
+
+constexpr bool
+f5 (int x)
+{
+  constexpr bool b = ({ switch (x) case 0: true; }) && false;  // { dg-error "could not convert" }
+  return false;
+}