Re: [PATCH] c++: Fix ICE during mangling of a conversion operator function template [PR126093]
Marek Polacek <[email protected]>
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Aug 07, 2026 at 02:45:50PM +0200, Jakub Jelinek wrote: > Hi! > > We ICE when trying to mangle the TEMPLATE_DECL of a conversion operator, > because FNDECL_USED_AUTO macro requires FUNCTION_DECL, but here we > have a TEMPLATE_DECL instead. > In this case, DECL_CONV_FN_TYPE contains the right type, so this patch > just guards the FNDECL_USED_AUTO macro use on FUNCTION_DECLs. > > So far tested on > GXX_TESTSUITE_STDS=98,11,14,17,20,23,26,29 make check-g++ -j32 -k RUNTESTFLAGS="dg.exp='reflect/*'" > Ok for trunk if it passes full bootstrap/regtest? FWIW, looks good. > 2026-08-07 Jakub Jelinek <[email protected]> > > PR c++/126093 > * mangle.cc (write_unqualified_name): Only check FNDECL_USED_AUTO > on FUNCTION_DECLs. > > * g++.dg/reflect/mangle1.C: Add 2 new tests for reflections of > conversion templates. > > --- gcc/cp/mangle.cc.jj 2026-08-06 13:24:02.000000000 +0200 > +++ gcc/cp/mangle.cc 2026-08-07 14:06:15.092252321 +0200 > @@ -1567,7 +1567,8 @@ write_unqualified_name (tree decl) > fn_type = get_mostly_instantiated_function_type (decl); > type = TREE_TYPE (fn_type); > } > - else if (FNDECL_USED_AUTO (decl)) > + else if (TREE_CODE (decl) == FUNCTION_DECL > + && FNDECL_USED_AUTO (decl)) > type = DECL_SAVED_AUTO_RETURN_TYPE (decl); > else > type = DECL_CONV_FN_TYPE (decl); > --- gcc/testsuite/g++.dg/reflect/mangle1.C.jj 2026-08-06 13:24:02.480925614 +0200 > +++ gcc/testsuite/g++.dg/reflect/mangle1.C 2026-08-07 14:30:30.275043881 +0200 > @@ -15,6 +15,10 @@ struct S : B { > int : 0; > static int var; > }; > +struct Q { > + template <typename T> > + operator T () { return T (); } > +}; > struct W { union {}; union {}; union {}; union {}; }; > template <auto> struct TCls {}; > template <auto> void TFn (); > @@ -65,6 +69,10 @@ namespace NS2 { > struct Z { > }; > struct AA { int a, b; }; > + struct Q { > + template <int N> > + operator int () { return N; } > + }; > } > > constexpr auto ctx = std::meta::access_context::current (); > @@ -147,6 +155,8 @@ baz (int x) > bar <241, ^^NS2::TCls> (); // class template > bar <250, ^^TFn> (); // function template > bar <251, ^^NS2::TFn> (); // function template > + bar <252, members_of (^^Q, ctx)[0]> (); // function template > + bar <253, members_of (^^NS2::Q, ctx)[0]> (); // function template > bar <260, ^^TVar> (); // variable template > bar <261, ^^NS2::TVar> (); // variable template > bar <270, ^^TAlias> (); // alias template > @@ -239,6 +249,8 @@ baz (int x) > // { dg-final { scan-assembler "_Z3barILi241ELDmct3NS24TClsEEvv" } } > // { dg-final { scan-assembler "_Z3barILi250ELDmft3TFnEEvv" } } > // { dg-final { scan-assembler "_Z3barILi251ELDmft3NS23TFnEEvv" } } > +// { dg-final { scan-assembler "_Z3barILi252ELDmft1QcvT_EEvv" } } > +// { dg-final { scan-assembler "_Z3barILi253ELDmft3NS21QcviEEvv" } } > // { dg-final { scan-assembler "_Z3barILi260ELDmvt4TVarEEvv" } } > // { dg-final { scan-assembler "_Z3barILi261ELDmvt3NS24TVarEEvv" } } > // { dg-final { scan-assembler "_Z3barILi270ELDmat6TAliasEEvv" } } Marek