[cxx-abi-dev] Mangling of reference temporaries
Hubert Tong
hstong at ca.ibm.com
Mon May 5 20:59:59 UTC 2014
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: hstong at ca.ibm.com
~ My heart is human ~ My blood is boiling ~ My brain, IBM ~
From: Jason Merrill <jason at redhat.com>
To: David Majnemer <david.majnemer at gmail.com>,
cxx-abi-dev at codesourcery.com,
Date: 05-05-2014 04:45 PM
Subject: Re: [cxx-abi-dev] Mangling of reference temporaries
Sent by: cxx-abi-dev-bounces at codesourcery.com
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
cxx-abi-dev at codesourcery.com
http://sourcerytools.com/cgi-bin/mailman/listinfo/cxx-abi-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20140505/b6165c7d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
URL: <http://sourcerytools.com/pipermail/cxx-abi-dev/attachments/20140505/b6165c7d/attachment.gif>
More information about the cxx-abi-dev
mailing list