On Sun, 3 Aug 2025, Jason Merrill wrote:

> On 8/1/25 11:16 AM, Patrick Palka wrote:
> > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK
> > for trunk and 15/14 after 15.2 is released?
> > 
> > -- >8 --
> > 
> > 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.
> > 
> >     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.
> > ---
> >   gcc/cp/constexpr.cc                              |  6 +++++-
> >   gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic19.C | 10 ++++++++++
> >   2 files changed, 15 insertions(+), 1 deletion(-)
> >   create mode 100644 gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic19.C
> > 
> > diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
> > index e051a50fe16e..4cf94afb9ca5 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 an actual dynamic_cast, and ignore direct calls
> > +        to abi::__dynamic_cast.  */
> > +     && DECL_ARTIFICIAL (fndecl));
> 
> With this patch, does constexpr dynamic_cast still work after including
> cxxabi.h?

Yes AFAICT.  I don't see duplicate_decls being called on __dynamic_cast
at all when including <cxxabi.h>, so presumably both declarations are
coexistiing.  Maybe because the synthesized declaration is pushed with
hidden=true or because it's not declared as extern "C" like the real
declaration?

> 
> Jason
> 
> 

Reply via email to