From: Jakub Jelinek Date: Fri, 8 Nov 2019 19:00:02 +0000 (+0100) Subject: backport: re PR c++/92343 ([[likely]]/[[unlikely]] prevent method from being a consta... X-Git-Tag: releases/gcc-9.3.0~408 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f3b59d4c6e375cb9941aa47258bb393dc38ea3a;p=thirdparty%2Fgcc.git backport: re PR c++/92343 ([[likely]]/[[unlikely]] prevent method from being a constant expression) Backported from mainline 2019-11-05 Jakub Jelinek 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 867b6e5b7f9b..c870d4a3817e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,6 +1,12 @@ 2019-11-08 Jakub Jelinek Backported from mainline + 2019-11-05 Jakub Jelinek + + PR c++/92343 + * constexpr.c (potential_constant_expression_1): Return true rather + than false for PREDICT_EXPR. + 2019-10-31 Jakub Jelinek PR c++/90947 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 806a812304eb..9845416a8121 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -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: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 161f91acf468..c3c660864bdf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,11 @@ 2019-11-08 Jakub Jelinek Backported from mainline + 2019-11-05 Jakub Jelinek + + PR c++/92343 + * g++.dg/cpp2a/attr-likely6.C: New test. + 2019-10-31 Jakub Jelinek 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 index 000000000000..a04021e50375 --- /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), "");