[Bug c++/124794] [reflection] ICE on member function template splicing
"cvs-commit at gcc dot gnu.org via Gcc-bugs" <[email protected]> Mon, 03 Aug 2026 21:27:47 +0000
| Newsgroups | gmane.comp.gcc.bugs |
|---|---|
| Message-ID | <[email protected]/bugzilla/> |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D124794 --- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Marek Polacek <[email protected]>: https://gcc.gnu.org/g:8fb57eda04f88f4e0d1cbbcc209533fd9689dd9d commit r17-2911-g8fb57eda04f88f4e0d1cbbcc209533fd9689dd9d Author: Marek Polacek <[email protected]> Date: Fri Jul 31 11:57:14 2026 -0400 c++/reflection: ICE with &template [:members_of():] [PR124794] Given struct C { template <class T> void f(T); }; we handle "&template [:^^C::f:]" correctly because the spliced expression is BASELINK<OVERLOAD<TEMPLATE_DECL f>>, binfo C> which is fine: we have an OVERLOAD around the TEMPLATE_DECL and lookup_member wrapped the whole thing in a BASELINK. But when we're splicing members_of(^^C, ac)[0], we ended up with OVERLOAD<TEMPLATE_DECL f>> and then go down the wrong path in cp_parser_splice_expression. splice already correctly adds the missing OVERLOAD but it also needs to (maybe) add a BASELINK. This patch also adjusts baselink_for_fns to gain a parameter controlling if we want to ignore currently_open_derived_class. It matters when we're in a member function of a class derived from C and the object argument of the -> is a different derived class, as exercised in splice17.C: pd->[:g1:] (42); in D2::mfn. There, if we didn't ignore currently_open_derived_class, the BASELINK would use D2 as the access_binfo, which is wrong because it has no derivation relationship to the object type (here D1). With this patch access_binfo will be C, which is what members_of gave us. PR c++/124794 gcc/cp/ChangeLog: * cp-tree.h (baselink_for_fns): Adjust declaration. * parser.cc (cp_parser_reflect_expression): Adjust the call to baselink_for_fns. * reflect.cc (splice): Call baselink_for_fns. * semantics.cc (baselink_for_fns): Add a bool parameter. If it's true, ignore currently_open_derived_class. gcc/testsuite/ChangeLog: * g++.dg/reflect/splice17.C: New test. Reviewed-by: Jason Merrill <[email protected]>=