aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/constexpr.cc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2022-10-14 09:07:01 -0400
committerPatrick Palka <ppalka@redhat.com>2022-10-14 09:07:01 -0400
commitd6a488f243acfac4bdbbb0eefbee3ae916159cf5 (patch)
tree176780cf7d0809701da5f0fba501c21771a4b78a /gcc/cp/constexpr.cc
parenta75e9bee7c23403d3cc7085a249f230de50c4c3e (diff)
downloadgcc-d6a488f243acfac4bdbbb0eefbee3ae916159cf5.zip
gcc-d6a488f243acfac4bdbbb0eefbee3ae916159cf5.tar.gz
gcc-d6a488f243acfac4bdbbb0eefbee3ae916159cf5.tar.bz2
c++ modules: ICE with dynamic_cast [PR106304]
The FUNCTION_DECL we build for __dynamic_cast has an empty DECL_CONTEXT but trees_out::tree_node expects FUNCTION_DECLs to have non-empty DECL_CONTEXT, thus we crash when streaming out the dynamic_cast in the below testcase. This patch naively fixes this by setting DECL_CONTEXT for __dynamic_cast appropriately. I suppose we should push it into the namespace too, like we do for __cxa_atexit which is similarly lazily declared. PR c++/106304 gcc/cp/ChangeLog: * constexpr.cc (cxx_dynamic_cast_fn_p): Check for abi_node instead of global_namespace. * rtti.cc (build_dynamic_cast_1): Set DECL_CONTEXT and DECL_SOURCE_LOCATION when building dynamic_cast_node. Push it into the namespace. gcc/testsuite/ChangeLog: * g++.dg/modules/pr106304_a.C: New test. * g++.dg/modules/pr106304_b.C: New test.
Diffstat (limited to 'gcc/cp/constexpr.cc')
-rw-r--r--gcc/cp/constexpr.cc2
1 files changed, 1 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index fb171a2..0366396 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -2088,7 +2088,7 @@ cxx_dynamic_cast_fn_p (tree fndecl)
{
return (cxx_dialect >= cxx20
&& id_equal (DECL_NAME (fndecl), "__dynamic_cast")
- && CP_DECL_CONTEXT (fndecl) == global_namespace);
+ && CP_DECL_CONTEXT (fndecl) == abi_node);
}
/* Often, we have an expression in the form of address + offset, e.g.