[cxx-abi-dev] Mangling of reference temporaries

Richard Smith richardsmith at google.com
Mon May 5 20:59:22 UTC 2014


On 5 May 2014 13:45, Jason Merrill <jason at redhat.com> wrote:

> On 05/04/2014 11:00 PM, David Majnemer wrote:
>
>> Consider the following:
>> struct A { const int (&x)[3]; };
>> struct B { const A (&x)[2]; };
>> template <typename T> B &&b = { { { { 1, 2, 3 } }, { { 4, 5, 6 } } } };
>> B &temp = b<void>;
>>
>> The temporaries created by instantiating b<void> must be the same in all
>> translation units.
>>
>
> Why?  As long as b<void> is itself unique, why does it matter what the
> name of the temporary it points to is?  All access to the temporary should
> go through the named variable.


Why should the optimizer not be able to look through the initializer? If I
have:

  extern const int &r = temp.x[1].x[2];

... then with -O, clang will statically initialize this to a subobject of
_ZGR1bIvE1, as the standard allows. And with:

  template<typename> struct S { static const int &r; };
  template<typename T> const int &S<T>::r = 1;
  extern constexpr const int &k = S<int>::r;

we are *required* to statically initialize 'k' to refer to the
lifetime-extended temporary. And it must be the same temporary in every TU.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20140505/d6379860/attachment.html>


More information about the cxx-abi-dev mailing list