c++gccdemangler

Ambiguity of de-mangled C++ symbols


_ZNSaIwEC1Ev
_ZNSaIwEC2Ev

These two C++ symbols differ but are demangled (using C++filt or similar utility) into the same form:

std::allocator<wchar_t>::allocator()
std::allocator<wchar_t>::allocator()

Why so? Could it be a demangler's defect or what else?


Solution

  • g++ uses the name mangling scheme (and other implementation details) specified by the Itanium ABI.

    In the section on mangling of constructors and destructors, we see:

    <ctor-dtor-name> ::= C1 # complete object constructor
                     ::= C2 # base object constructor
                     ::= C3 # complete object allocating constructor
                     ::= D0 # deleting destructor
                     ::= D1 # complete object destructor
                     ::= D2 # base object destructor
    

    So the C1 and C2 pieces of the mangled names you asked about imply information which is important to the C++ system and must be correctly linked individually. But that information is difficult to briefly explain in a pseudo-code declaration, so the demangling function just describes both symbols identically.

    Though since std::allocator<T> normally does not have any virtual base classes, it's likely that the two symbols actually point at the same code address, but g++ just provides both linker symbols for consistency.