re PR c++/71728 (ICE with goto in statement-expression inside a condition)
authorJakub Jelinek <jakub@redhat.com>
Thu, 21 Jul 2016 18:22:32 +0000 (20:22 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 21 Jul 2016 18:22:32 +0000 (20:22 +0200)
PR c++/71728
* constexpr.c (potential_constant_expression_1) <case GOTO_EXPR>:
Replace assert with test, return false if the goto isn't break
or continue.  Formatting fix.

* g++.dg/other/pr71728.C: New test.

From-SVN: r238601

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

index e7f5cb0dfbd59a6c1cba39a062f09deb4e76cb90..0ba456c76e5256487c216a5aaba0a16e43b641ea 100644 (file)
@@ -1,3 +1,10 @@
+2016-07-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/71728
+       * constexpr.c (potential_constant_expression_1) <case GOTO_EXPR>:
+       Replace assert with test, return false if the goto isn't break
+       or continue.  Formatting fix.
+
 2016-07-21  Richard Biener  <rguenther@suse.de>
 
        * vtable-class-hierarchy.c (vtv_generate_init_routine): Set
index 240c606f82c817bbeea47d97c9f1f4c1462a09b5..f139260fb8b8a5b66375c6deaba6579369ec6cfa 100644 (file)
@@ -5289,10 +5289,12 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict,
     case GOTO_EXPR:
       {
        tree *target = &TREE_OPERAND (t, 0);
-       /* Gotos representing break and continue are OK; we should have
-          rejected other gotos in parsing.  */
-       gcc_assert (breaks (target) || continues (target));
-       return true;
+       /* Gotos representing break and continue are OK.  */
+       if (breaks (target) || continues (target))
+         return true;
+       if (flags & tf_error)
+         error ("%<goto%> is not a constant-expression");
+       return false;
       }
 
     default:
@@ -5300,7 +5302,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict,
        return false;
 
       sorry ("unexpected AST of kind %s", get_tree_code_name (TREE_CODE (t)));
-      gcc_unreachable();
+      gcc_unreachable ();
       return false;
     }
 #undef RECUR
index d0b0c1d165dc02537f8e550091094f061aa307d1..0c03e52838d7bc48a3404bfcdaf71aebdffa1b01 100644 (file)
@@ -1,3 +1,8 @@
+2016-07-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/71728
+       * g++.dg/other/pr71728.C: New test.
+
 2016-07-21  James Greenhalgh  <james.greenhalgh@arm.com>
 
        * gcc.dg/ifcvt-2.c: Use parameter to guide if-conversion heuristics.
diff --git a/gcc/testsuite/g++.dg/other/pr71728.C b/gcc/testsuite/g++.dg/other/pr71728.C
new file mode 100644 (file)
index 0000000..b70e3c2
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/71728
+// { dg-do compile }
+// { dg-options "-std=gnu++14 -Wall" }
+
+int
+foo ()
+{
+  if (({ goto test; test: 1; }) != 1)
+    return 1;
+  return 2;
+}