Is escaping of a temp variable valid?
Joey Ye
joey.ye.cc@gmail.com
Mon Aug 18 09:39:00 GMT 2014
On Fri, Aug 15, 2014 at 6:33 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Fri, Aug 15, 2014 at 10:45 AM, Joey Ye <joey.ye.cc@gmail.com> wrote:
>> Running into an unexpected result with GCC with following case, but
>> not sure if it is a valid C++ case.
>>
>> #define nullptr 0
>> enum nonetype { none };
>>
>> template<typename T>
>> class class_zoo {
>> public:
>> const T *data;
>> int length;
>>
>> class_zoo (nonetype) : data (nullptr), length (0) {}
>> class_zoo (const T &e) : data (&e), length (1) {}
>
> Capturing a const referece via a pointer is error-prone as for
> example literal constants class_zoo<const int *> zoo(0)
> have associated objects that live only throughout the function
> call.
Thanks for confirming this. But do you imply capturing a non-const
reference via a pointer is safe, which I would assume it unsafe
either?
- Joey
>
> So clearly your testcase is invalid.
>
> Richard.
More information about the Gcc
mailing list