From 81012684569cfb64b0274f117d68740cde52ffdd Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 5 Nov 2019 11:16:39 +0100 Subject: [PATCH] re PR c++/92343 ([[likely]]/[[unlikely]] prevent method from being a constant expression) 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 | 4 ++++ gcc/cp/constexpr.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp2a/attr-likely6.C | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/attr-likely6.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9b16121c503..2bc6037037c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2019-11-05 Jakub Jelinek + 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 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 84ed7accd7d..72de2efb560 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -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: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index db8798b9c11..9be2ab4ac45 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-11-05 Jakub Jelinek + + PR c++/92343 + * g++.dg/cpp2a/attr-likely6.C: New test. + 2019-11-05 Martin Liska 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 index 00000000000..a04021e5037 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/attr-likely6.C @@ -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), ""); -- 2.30.2