c++: undiagnosed error_mark_node from cp_build_c_cast [PR112658]
commit5764825aed613f201a8bc47e5b239027a39691f0
authorPatrick Palka <ppalka@redhat.com>
Fri, 8 Dec 2023 18:33:55 +0000 (8 13:33 -0500)
committerPatrick Palka <ppalka@redhat.com>
Fri, 8 Dec 2023 18:33:55 +0000 (8 13:33 -0500)
tree654cb27057815c9593aab71e627f984f4dc2a91d
parentd468718c9a097aeb8794fb1a2df6db2c1064d7f7
c++: undiagnosed error_mark_node from cp_build_c_cast [PR112658]

When cp_build_c_cast commits to an erroneous const_cast, we neglect to
replay errors from build_const_cast_1 which can lead to us incorrectly
accepting (and "miscompiling") the cast, or triggering the assert in
finish_expr_stmt.

This patch fixes this oversight.  This was the original fix for the ICE
in PR112658 before r14-5941-g305a2686c99bf9 made us accept the testcase
there after all.  I wasn't able to come up with an alternate testcase for
which this fix has an effect anymore, but below is a reduced version of
the PR112658 testcase (accepted ever since r14-5941) for good measure.

PR c++/112658
PR c++/94264

gcc/cp/ChangeLog:

* typeck.cc (cp_build_c_cast): If we're committed to a const_cast
and the result is erroneous, call build_const_cast_1 a second
time to issue errors.  Use complain=tf_none instead of =false.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist-array20.C: New test.
gcc/cp/typeck.cc
gcc/testsuite/g++.dg/cpp0x/initlist-array20.C [new file with mode: 0644]