]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: fix constexpr cast from void* diag issue [PR116741]
authorMarek Polacek <polacek@redhat.com>
Tue, 17 Sep 2024 18:34:30 +0000 (14:34 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 17 Sep 2024 21:04:20 +0000 (17:04 -0400)
commitd6d8445c85509b66a59aa6247ad7b2cfeab17725
tree23072283ba1e3363c7a5ac78e3cc6f7c498eb49c
parent7ca486889b1b1c7e7bcbbca3b6caa103294ec07d
c++: fix constexpr cast from void* diag issue [PR116741]

The result of build_fold_indirect_ref can be a COMPONENT_REF in
which case using DECL_SOURCE_LOCATION will crash.  Look at its op1
instead.

PR c++/116741

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_constant_expression) <case CONVERT_EXPR>: If
the result of build_fold_indirect_ref is a COMPONENT_REF, use its op1.
Check DECL_P before calling inform.

gcc/testsuite/ChangeLog:

* g++.dg/cpp26/constexpr-voidptr4.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/constexpr.cc
gcc/testsuite/g++.dg/cpp26/constexpr-voidptr4.C [new file with mode: 0644]