Name mangling question

nasgaard at ca.ibm.com nasgaard at ca.ibm.com
Wed Nov 27 11:53:53 UTC 2002


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.

I believe the following should be the productions followed to mangle the
name:

Mangling declaration for: locale::_Impl::foo
 <mangled-name> ::= _Z <encoding>
  <encoding> ::= <function name> <bare-function-type>
   <name> ::= <nested-name>
    <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
     <prefix> ::= <prefix> <unqualified-name>
      <prefix> ::= <prefix> <unqualified-name>
       <prefix> ::= empty
       <unqualified-name> ::= <source-name>
        <source-name> ::= locale
        Looking for 6locale
        Adding: 6locale as S_
      <unqualified-name> ::= <source-name>
       <source-name> ::= _Impl
       Looking for 6locale5_Impl
       Adding: 6locale5_Impl as S0_
     <unqualified-name> ::= <source-name>
      <source-name> ::= foo
   <bare-function-type> ::= <signature type>+
    <type> ::= R <type>
     <type> ::= <cv-qualifiers> <type>
      <type> ::= <class-enum-type>
       <class-enum-type> ::= <name>
        <name> ::= <nested-name>
         <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name>
E
          <prefix> ::= <prefix> <unqualified-name>
           <prefix> ::= empty
           <unqualified-name> ::= <source-name>
            <source-name> ::= locale
          Looking for 6locale
          Found: S_
          <unqualified-name> ::= <source-name>
           <source-name> ::= _Impl
      Looking for N6locale5_ImplE
      Adding: N6locale5_ImplE as S1_
    Looking for RN6locale5_ImplE
    Adding: RN6locale5_ImplE as S2_
Mangled name for: locale::_Impl::foo is: _ZN6locale5_Impl3fooERNS_5_ImplE


Howard W. Nasgaard
C++ Compiler Development
e-mail: nasgaard at ca.ibm.com
C2/KD2/8200/MKM
905-413-3683
Tie: 969-3683




More information about the cxx-abi-dev mailing list