diff options
author | Patrick Palka <ppalka@redhat.com> | 2025-08-04 16:43:33 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2025-08-04 16:43:33 -0400 |
commit | b51ca7d2f548ffdad03fa779e3ff7bcc3441ff03 (patch) | |
tree | 1cad52414ac192a689947fdbcdb07685f76de642 /gcc/cp/constexpr.cc | |
parent | ac421ac33ed64619f79b8f3c4edb4fb30b1640c5 (diff) | |
download | gcc-b51ca7d2f548ffdad03fa779e3ff7bcc3441ff03.zip gcc-b51ca7d2f548ffdad03fa779e3ff7bcc3441ff03.tar.gz gcc-b51ca7d2f548ffdad03fa779e3ff7bcc3441ff03.tar.bz2 |
c++: constexpr evaluation of abi::__dynamic_cast [PR120620]
r13-3299 changed our internal declaration of __dynamic_cast to reside
inside the abi/__cxxabiv1:: namespace instead of the global namespace,
matching the real declaration. This inadvertently made us now attempt
constexpr evaluation of user-written calls to abi::__dynamic_cast since
cxx_dynamic_cast_fn_p now also returns true for them, but we're not
prepared to handle arbitrary calls to __dynamic_cast, and therefore ICE.
This patch restores cxx_dynamic_cast_fn_p to return true only for
synthesized calls to __dynamic_cast, which can be distinguished by
DECL_ARTIFICIAL, since apparently the synthesized declaration of
__dynamic_cast doesn't get merged with the actual declaration.
PR c++/120620
gcc/cp/ChangeLog:
* constexpr.cc (cxx_dynamic_cast_fn_p): Return true only
for synthesized __dynamic_cast.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/constexpr-dynamic19.C: New test.
* g++.dg/cpp2a/constexpr-dynamic1a.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
Diffstat (limited to 'gcc/cp/constexpr.cc')
-rw-r--r-- | gcc/cp/constexpr.cc | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index be24ae2..142579a 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -3240,7 +3240,11 @@ cxx_dynamic_cast_fn_p (tree fndecl) { return (cxx_dialect >= cxx20 && id_equal (DECL_NAME (fndecl), "__dynamic_cast") - && CP_DECL_CONTEXT (fndecl) == abi_node); + && CP_DECL_CONTEXT (fndecl) == abi_node + /* Only consider implementation-detail __dynamic_cast calls that + correspond to a dynamic_cast, and ignore direct calls to + abi::__dynamic_cast. */ + && DECL_ARTIFICIAL (fndecl)); } /* Often, we have an expression in the form of address + offset, e.g. |