C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Specify the mangled name

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Sun, 2 Feb 2025 23:53:16 +0300
On 2/2/25 22:50, Frederick Virchanza Gotham via Std-Proposals wrote:
> A few days ago here on the mailing list, a person posted that some
> programmers are avoiding doing:
>
> typedef vector<int> IntVec;
>
> and instead are doing:
>
> class IntVec : public vector<int> {
> . . .
> };
>
> simply because the former gets mangled to something horrible, and the
> latter gets mangled to something that is easy to spot in the debugger.
>
> The C++ Standard doesn't mention the word 'mangle', however it is at
> least on some level aware of mangling because you can write "extern C"
> to tell the compiler not to mangle a name -- or at least to mangle it
> the way it would get mangled if it were C instead of C++.

That's not quite what it means. It specifies language linkage for the
symbols affected by `extern "C"`, and how the language linkage is
implemented is out of scope of the C++ standard. Symbol mangling is one
possible implementation, but not necessarily the only one.

> What if the original typedef could be rewritten as:
>
> typedef vector<int> IntVec <=> mangle("IntVec");
>
> And also when declaring or defining a class as follows:
>
> class IntVec <=> mangled("SomeOtherName");
>
> class IntVec : public vector<int> <=> mangled("SomeOtherName") {
> . . .
> };
>
> Would this be useful in C++29?

I don't think changing symbol mangling just to see prettier names in the
debugger is enough of a justification for a major syntax change. I don't
find this use case convincing at all, in fact. There may be other use
cases where the user needs a strict control over the symbol names, like
satisfying some ABI requirements to integrate with the target
environment. That still is not enough for a major syntax change, but may
be enough for an attribute. A non-standard one, too, since the standard
does not define implementation details such as name mangling (rightfully
so). For example, GCC has an attribute `alias` that can be used to that
effect.

https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alias-function-attribute

Received on 2025-02-02 20:53:20