diff options
author | Marek Polacek <polacek@redhat.com> | 2024-09-17 14:34:30 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2024-09-17 17:04:20 -0400 |
commit | d6d8445c85509b66a59aa6247ad7b2cfeab17725 (patch) | |
tree | 23072283ba1e3363c7a5ac78e3cc6f7c498eb49c /gcc/cp | |
parent | 7ca486889b1b1c7e7bcbbca3b6caa103294ec07d (diff) | |
download | gcc-d6d8445c85509b66a59aa6247ad7b2cfeab17725.zip gcc-d6d8445c85509b66a59aa6247ad7b2cfeab17725.tar.gz gcc-d6d8445c85509b66a59aa6247ad7b2cfeab17725.tar.bz2 |
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>
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/constexpr.cc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index c3668b0..f6fd059 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -8201,8 +8201,11 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, TREE_TYPE (op), TREE_TYPE (TREE_TYPE (sop)), TREE_TYPE (type)); tree obj = build_fold_indirect_ref (sop); - inform (DECL_SOURCE_LOCATION (obj), - "pointed-to object declared here"); + if (TREE_CODE (obj) == COMPONENT_REF) + obj = TREE_OPERAND (obj, 1); + if (DECL_P (obj)) + inform (DECL_SOURCE_LOCATION (obj), + "pointed-to object declared here"); } *non_constant_p = true; return t; |