]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/92343 ([[likely]]/[[unlikely]] prevent method from being a consta...
authorJakub Jelinek <jakub@redhat.com>
Fri, 8 Nov 2019 19:00:02 +0000 (20:00 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 8 Nov 2019 19:00:02 +0000 (20:00 +0100)
Backported from mainline
2019-11-05  Jakub Jelinek  <jakub@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.

From-SVN: r277988

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

index 867b6e5b7f9bc5bfadb868c8c0776ddae2d11053..c870d4a3817efa862e2e0fc87b38d4c77e46f9e6 100644 (file)
@@ -1,6 +1,12 @@
 2019-11-08  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-11-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/92343
+       * constexpr.c (potential_constant_expression_1): Return true rather
+       than false for PREDICT_EXPR.
+
        2019-10-31  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/90947
index 806a812304eb36030348bba841389d87a53b7258..9845416a8121ae9c03ce08702be9daf9cc2343b4 100644 (file)
@@ -5925,6 +5925,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
     case LABEL_DECL:
     case LABEL_EXPR:
     case CASE_LABEL_EXPR:
+    case PREDICT_EXPR:
     case CONST_DECL:
     case SIZEOF_EXPR:
     case ALIGNOF_EXPR:
@@ -6759,7 +6760,6 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
 
     case CLEANUP_STMT:
     case EMPTY_CLASS_EXPR:
-    case PREDICT_EXPR:
       return false;
 
     case GOTO_EXPR:
index 161f91acf468e721643ecb79071f0ccd3cef5408..c3c660864bdf29449bbb55867bf8171eee8c63ed 100644 (file)
@@ -1,6 +1,11 @@
 2019-11-08  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-11-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/92343
+       * g++.dg/cpp2a/attr-likely6.C: New test.
+
        2019-10-31  Jakub Jelinek  <jakub@redhat.com>
 
        PR preprocessor/92296
diff --git a/gcc/testsuite/g++.dg/cpp2a/attr-likely6.C b/gcc/testsuite/g++.dg/cpp2a/attr-likely6.C
new file mode 100644 (file)
index 0000000..a04021e
--- /dev/null
@@ -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), "");