[cfe-dev] GCC's "Temporaries May Vanish Before You Expect"

Sean Silva silvas at purdue.edu
Wed Sep 12 17:17:17 PDT 2012


> No, that's fine. Temporaries are destroyed "at the end of a full-expression", which is basically "the outermost expression". So the temporary will stay live until the call to doSomething completes.

Oh, ok, that's what I though. Looking at the OP a bit closer, I see
now that the problem isn't that temporary per se, it is stashing the
pointer to it in S.

>> Would it be possible to make dyn_cast a bit smarter so that it will
>> look into an iterator's member typedefs and automatically do the
>> trivial &* stuff itself?
>
> In theory, yes. In practice, I'm not sure if we want simplify_type to be that smart. I haven't thought it through, though.

The discussion pretty quickly veered into macro/#ifdef territory as a
means to solve the problem, perhaps this would be the least bad
workaround.

--Sean Silva

On Wed, Sep 12, 2012 at 8:11 PM, Jordan Rose <jordan_rose at apple.com> wrote:
>
> On Sep 12, 2012, at 17:08 , Sean Silva <silvas at purdue.edu> wrote:
>
>> Does that mean that:
>>
>> doSomething(StrRef.str().c_str());
>>
>> is unsafe?
>>
>> because I've seen a couple of those around.
>
> No, that's fine. Temporaries are destroyed "at the end of a full-expression", which is basically "the outermost expression". So the temporary will stay live until the call to doSomething completes.
>
>
>>>  I->getAs<CFGStmt>()
>>>
>>> and
>>>
>>>  dyn_cast<CFGStmt>(&*I)
>>>
>>> , the latter of which is slightly more ugly.
>>
>> Would it be possible to make dyn_cast a bit smarter so that it will
>> look into an iterator's member typedefs and automatically do the
>> trivial &* stuff itself?
>
> In theory, yes. In practice, I'm not sure if we want simplify_type to be that smart. I haven't thought it through, though.
>



More information about the cfe-dev mailing list