[PATCH] c++: Add std::to_underlying to the set of stdlib functions that are always folded
Ville Voutilainen
ville.voutilainen@gmail.com
Tue May 13 20:42:13 GMT 2025
On Tue, 13 May 2025 at 23:34, Jason Merrill <jason@redhat.com> wrote:
>
> On 5/13/25 4:29 PM, Ville Voutilainen wrote:
> > On Tue, 13 May 2025 at 23:23, Jason Merrill <jason@redhat.com> wrote:
> >>> /* Check that the return and argument types are sane before
> >>> folding. */
> >>> - if (INDIRECT_TYPE_P (TREE_TYPE (x))
> >>> - && INDIRECT_TYPE_P (TREE_TYPE (r)))
> >>> + if (id_equal (DECL_NAME (callee), "to_underlying")
> >>> + || (INDIRECT_TYPE_P (TREE_TYPE (x))
> >>> + && INDIRECT_TYPE_P (TREE_TYPE (r))))
> >>
> >> Maybe instead of INDIRECT_TYPE_P, check ! AGGREGATE_TYPE_P ? I'm not
> >> sure how much sanity checking we need here, maybe we should just trust
> >> the library.
> >
> > I.. ..don't think AGGREGATE_TYPE_P is right?
>
> I was suggesting *not* AGGREGATE_TYPE_P, because build_nop doesn't work
> for such types.
Ah, yes, got it. I did spot the 'not' but was wondering whether that
covers all the right cases, but for references and enumerators, I
guess
it would.
> > It seems to me that this
> > sanity check is checking that it's a cast between
> > references for the other ones, and that's just unsuitable for
> > to_underlying. I would suggest just removing that sanity
> > check and trusting the library.
>
> That's fine too.
I'll test the attached.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: to_underlying_fold.diff
Type: text/x-patch
Size: 2235 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20250513/279b0e3c/attachment-0001.bin>
More information about the Libstdc++
mailing list