[cxx-abi-dev] Mangling sizeof

Doug Gregor doug.gregor at gmail.com
Thu Mar 5 16:52:00 UTC 2009


On Wed, Mar 4, 2009 at 8:03 PM, Jason Merrill <jason at redhat.com> wrote:
> I've been looking at some old GCC bug reports and noticed that my recent
> mangling improvements didn't extend the use of the expression type stubs to
> sizeof expressions, so we still run into mangling holes in that context.
>  What do people think about using the type stubs in sizeof expressions as
> well?  This would break ABI compatibility with most existing uses of sizeof
> in template signatures, but I suspect those are very few currently because
> of the limitations of expression mangling (prior to the recent
> enhancements).

Jason and I discussed this a bit further, and this change can lead to
collisions in mangled names. Here's an (admittedly ugly) example:

  template<int> struct A { };

  template<typename T> A<sizeof(T(T() + T()))> foo(); // #1
  template<typename T> A<sizeof(T(T() - T()))> foo(); // #2

  struct X { };

Now, in one translation unit we have

  X operator+(X, X);

and we instantiate foo<X> we get an instantiation of #1.

In another translation unit we have

  X operator+(X, X)

and we instantiate foo<X> we get an instantiation of #2.

This program is well-formed (there is no ODR violation, since the
signatures of the two function templates are different), but the two
foo<X>'s would have the same mangled name because T(T() + T()) and
T(T() - T()) have the same type stub.

  - Doug



More information about the cxx-abi-dev mailing list