re PR c++/92343 ([[likely]]/[[unlikely]] prevent method from being a constant expression)
authorJakub Jelinek <jakub@redhat.com>
Tue, 5 Nov 2019 10:16:39 +0000 (11:16 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 5 Nov 2019 10:16:39 +0000 (11:16 +0100)
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: r277819

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

index 9b16121c503d3010da396948514a4897bbe78969..2bc6037037cdcf4d80ca10aa11173195173e97fa 100644 (file)
@@ -1,5 +1,9 @@
 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.
+
        * decl.c (omp_declare_variant_finalize_one): Call
        declare_simd_adjust_this not just on the context, but also on the
        variant-id expression for methods.  Don't call
index 84ed7accd7d4717231fdacbb1bfdbfe735166797..72de2efb56009f6c4742ce20de73198b5018b39b 100644 (file)
@@ -6493,6 +6493,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:
@@ -7354,7 +7355,6 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
       return true;
 
     case EMPTY_CLASS_EXPR:
-    case PREDICT_EXPR:
       return false;
 
     case GOTO_EXPR:
index db8798b9c112e0a0c80f68efb001863d8eca5c3e..9be2ab4ac451fb81b2a37232b0c543e2882fca5a 100644 (file)
@@ -1,3 +1,8 @@
+2019-11-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/92343
+       * g++.dg/cpp2a/attr-likely6.C: New test.
+
 2019-11-05  Martin Liska  <mliska@suse.cz>
 
        PR c++/92339
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), "");