]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: -Waddress and if constexpr [PR94554]
authorJason Merrill <jason@redhat.com>
Thu, 23 Jun 2022 04:24:22 +0000 (00:24 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 23 Jun 2022 15:07:21 +0000 (11:07 -0400)
commit124a9e08b7a83795bd4d09001955f0eef68ecd00
tree95a4355dedee97c8354af62b54c689262cbf461f
parent6e4d5300c1f62c3f0cd1bf859b0ee6bb4e31e434
c++: -Waddress and if constexpr [PR94554]

Like we avoid various warnings for seemingly tautological expressions when
substituting a template, we should avoid warning for the implicit conversion
to bool in an if statement.  I considered also doing this for the conditions
in loop expressions, but that seems unnecessary, as a loop condition is
unlikely to be a constant.

The change to finish_if_stmt_cond isn't necessary since dependent_operand_p
looks through IMPLICIT_CONV_EXPR, but makes it more constent with
e.g. build_x_binary_op that determines the type of an expression and then
builds it using the original operands.

PR c++/94554

gcc/cp/ChangeLog:

* pt.cc (dependent_operand_p): Split out from...
(tsubst_copy_and_build): ...here.
(tsubst_expr) [IF_STMT]: Use it.
* semantics.cc (finish_if_stmt_cond): Keep the pre-conversion
condition in the template tree.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/constexpr-if38.C: New test.
gcc/cp/pt.cc
gcc/cp/semantics.cc
gcc/testsuite/g++.dg/cpp1z/constexpr-if38.C [new file with mode: 0644]