]> gcc.gnu.org Git - gcc.git/commit
c++: wrong error with constexpr COMPOUND_EXPR [PR105321]
authorMarek Polacek <polacek@redhat.com>
Wed, 20 Apr 2022 20:02:52 +0000 (16:02 -0400)
committerMarek Polacek <polacek@redhat.com>
Fri, 22 Apr 2022 21:00:08 +0000 (17:00 -0400)
commitafec66b054a7603ef394dc712ccbba37ae645fd9
tree92502fc589dd2850ccdb594a1fff7b2c912796fa
parent47c74508116cb5959686b183374dfe97a5e4fb37
c++: wrong error with constexpr COMPOUND_EXPR [PR105321]

Here we issue a bogus error for the first assert in the test.  Therein
we have

<retval> = (void) (VIEW_CONVERT_EXPR<bool>(yes) || handle_error ());, VIEW_CONVERT_EXPR<int>(value);

which has a COMPOUND_EXPR, so we get to cxx_eval_constant_expression
<case COMPOUND_EXPR>.  The problem here is that we call

7044             /* Check that the LHS is constant and then discard it.  */
7045             cxx_eval_constant_expression (ctx, op0,
7046                                           true, non_constant_p, overflow_p,
7047                                           jump_target);

where lval is always true, so the PARM_DECL 'yes' is not evaluated into
its value.

Fixed by always passing false for 'lval' in cxx_eval_logical_expression;
there's no case where we actually expect an lvalue from a TRUTH_*.

PR c++/105321

gcc/cp/ChangeLog:

* constexpr.c (cxx_eval_logical_expression): Always pass false for lval
to cxx_eval_constant_expression.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-105321.C: New test.

(cherry picked from commit 93b65ed9706e2ceb4be7b28c9ff9be759e68a614)
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/cpp0x/constexpr-105321.C [new file with mode: 0644]
This page took 0.053655 seconds and 5 git commands to generate.