This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Is escaping of a temp variable valid?


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]