C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Specify the mangled name

From: Jeremy Rifkin <rifkin.jer_at_[hidden]>
Date: Sun, 2 Feb 2025 14:59:29 -0600
> It would be useful where two types are identical but you want to give
> them different names, for example:
> typedef vector<int> IntVec;
> typedef vector<int> CollectionOfSerialNumbers <=>
> mangle("CollectionOfSerialNumbers");
> This will make it easy to differentiate overloaded functions:
> void Func(IntVec &);
> void Func(CollectionOfSerialNumbers &);

This isn't how typedef works in C++. Typedef creates an alias, neither
`IntVec` nor `CollectionOfSerialNumbers` are types. You can't overload with
them in the way you want to.

> Assume there's no previous ABI and that IntVec is a new type. Can't
> break ABI if there's no old ABI to break.

Even if this were a valid assumption it would still break ABI because
typedefs do not introduce new types. Think about this: What do you want `
typedef vector<int> CollectionOfSerialNumbers <=>
mangle("CollectionOfSerialNumbers");` to do? Change the mangling of
`std::vector<int>` in the TU? Everywhere? What if `std::vector<int>` is
used in one place and `CollectionOfSerialNumbers` in another?


I think what you may desire is not the ability to control mangling but
rather the ability to do a strong typedef, where typedef would actually
make different types. I don't know if a proposal has ever been written for
these before but the idea isn't new.

Cheers,
Jeremy


On Sun, Feb 2, 2025 at 2:52 PM Frederick Virchanza Gotham via Std-Proposals
<std-proposals_at_[hidden]> wrote:

> On Sun, Feb 2, 2025 at 8:01 PM Jeremy Rifkin wrote:
> >
> > Most people would never care about the mangled name and demangles are
> easy to use.
>
>
> It would be useful where two types are identical but you want to give
> them different names, for example:
>
> typedef vector<int> IntVec;
> typedef vector<int> CollectionOfSerialNumbers <=>
> mangle("CollectionOfSerialNumbers");
>
> This will make it easy to differentiate overloaded functions:
>
> void Func(IntVec &);
> void Func(CollectionOfSerialNumbers &);
>
>
> > > What if the original typedef could be rewritten as:
> > > typedef vector<int> IntVec <=> mangle("IntVec");
> >
> > This wouldn't work, it would break ABI.
>
>
> Assume there's no previous ABI and that IntVec is a new type. Can't
> break ABI if there's no old ABI to break.
>
>
> > > class IntVec : public vector<int> <=> mangled("SomeOtherName")
> >
> > Why would you need to do that if you could specify the mangling of your
> typedef?
>
>
> I was just showing that any given class could be given a custom
> mangled name, but yeah you're right that there's no reason why a
> programmer would inherit from vector and also specify a custom mangled
> name.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2025-02-02 20:59:43