The temporary can be used in constant expressions I think.

> cat q.cc
struct A { int pad; const int (&x)[1]; };

template <typename T>
struct B {
   static constexpr A a = { 0, { 0 } };
   static constexpr const int *x = a.x;
};

template <typename T> constexpr A B<T>::a;

const void *foo();

extern "C" int printf(const char *, ...);
int main() {
   printf("%p\n", static_cast<const void *>(B<short>::x));
   printf("%p\n", foo());
}
Return:  0x00:0

> cat q2.cc
struct A { int pad; const int (&x)[1]; };

template <typename T>
struct B {
   static constexpr A a = { 0, { 0 } };
   static constexpr const int *x = a.x;
};

template <typename T> constexpr A B<T>::a;

const void *foo() {
   return B<short>::x;
}
Return:  0x00:0

Hubert S K Tong
C++ Front-End and Runtime Development for XL C/C++
IBM Canada Ltd, C2/YGH/8200/MKM
8200 Warden Ave, Markham ON  L6G 1C7
Canada
Phone:  +1 (905) 413-4207; ITN:  23134207
E-mail:  [email protected]

~ My heart is human ~ My blood is boiling ~ My brain, IBM ~



From:   Jason Merrill <[email protected]>
To:     David Majnemer <[email protected]>,
            [email protected],
Date:   05-05-2014 04:45 PM
Subject:        Re: [cxx-abi-dev] Mangling of reference temporaries
Sent by:        [email protected]



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.

Jason

_______________________________________________
cxx-abi-dev mailing list
[email protected]
http://sourcerytools.com/cgi-bin/mailman/listinfo/cxx-abi-dev

_______________________________________________
cxx-abi-dev mailing list
[email protected]
http://sourcerytools.com/cgi-bin/mailman/listinfo/cxx-abi-dev

Reply via email to