This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Is escaping of a temp variable valid?
- From: Joey Ye <joey dot ye dot cc at gmail dot com>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Mon, 18 Aug 2014 17:39:20 +0800
- Subject: Re: Is escaping of a temp variable valid?
- Authentication-results: sourceware.org; auth=none
- References: <CAL0py27SobqjquCSSS-9jVG65bc6ooyGBsMsuasHwnUxqzjETg at mail dot gmail dot com> <CAFiYyc0970LW1YgXoZfEzcQu2+6-3XOG+7OtbUCw40BYcR_SjA at mail dot gmail dot com>
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.