Hi!

When Martin Liska added PREDICT_EXPR to potential_constant_expression_1,
it was with goto in mind and in that case goto isn't a potential
constant expression, but when the {,un}likely attributes are used on other
statements, they are valid.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2019-11-05  Jakub Jelinek  <ja...@redhat.com>

        PR c++/92343
        * constexpr.c (potential_constant_expression_1): Return true rather
        than false for PREDICT_EXPR.

        * g++.dg/cpp2a/attr-likely6.C: New test.

--- gcc/cp/constexpr.c.jj       2019-11-02 00:26:48.965846855 +0100
+++ gcc/cp/constexpr.c  2019-11-04 09:53:35.070621487 +0100
@@ -6493,6 +6493,7 @@ potential_constant_expression_1 (tree t,
     case LABEL_DECL:
     case LABEL_EXPR:
     case CASE_LABEL_EXPR:
+    case PREDICT_EXPR:
     case CONST_DECL:
     case SIZEOF_EXPR:
     case ALIGNOF_EXPR:
@@ -7354,7 +7355,6 @@ potential_constant_expression_1 (tree t,
       return true;
 
     case EMPTY_CLASS_EXPR:
-    case PREDICT_EXPR:
       return false;
 
     case GOTO_EXPR:
--- gcc/testsuite/g++.dg/cpp2a/attr-likely6.C.jj        2019-11-04 
09:54:50.126485303 +0100
+++ gcc/testsuite/g++.dg/cpp2a/attr-likely6.C   2019-11-04 09:55:21.001017926 
+0100
@@ -0,0 +1,14 @@
+// PR c++/92343
+// { dg-do compile { target c++14 } }
+
+constexpr bool
+foo (bool x)
+{
+  if (x)
+    [[unlikely]] return true;
+  else
+    [[likely]] return false;
+}
+
+static_assert (foo (true), "");
+static_assert (!foo (false), "");

        Jakub

Reply via email to