[cxx-abi-dev] Name mangling question

Mark Mitchell mark at codesourcery.com
Wed Nov 27 15:43:13 UTC 2002



--On Wednesday, November 27, 2002 06:53:53 AM -0500 "nasgaard at ca.ibm.com" 
<nasgaard at ca.ibm.com> wrote:

> I am having a problem understanding the mangling of function parameters
> for functions in a nested class.  Given the following test case:
>
> struct locale {
>    struct _Impl
>    {
>       void foo(_Impl&);
>    };
> };
>
> int main() {
>    locale::_Impl i;
>    i.foo(i);
> }
>
> g+ mangles this name as _ZN6locale5_Impl3fooERS0_
>
> It would seem that 6locale would have S_ as a substitution, and
> 6locale5_Impl would have S0_.  Given that the parameter is a nested name
> and so should be within N/E delimiters,  I don't see how g++ arives at
> that mangling.

One of the alternatives for the <type> production is <substitution>.

Therefore, you should never get to <nested-name> for the parameter.

Here is the mistake:

    <type> ::= R <type>
     <type> ::= <cv-qualifiers> <type>

That last line should be:

     <type> ::= <substitution>

There are definitely cases where two distinct strings will demangle to
the same name.  That's because the demangler doesn't try to check that
the input string uses substitutions.

-- 
Mark Mitchell                mark at codesourcery.com
CodeSourcery, LLC            http://www.codesourcery.com>



More information about the cxx-abi-dev mailing list