On Sun, Jul 7, 2013 at 10:33 PM, Tommy M. McGuire <[email protected]> wrote:

> On 07/07/2013 02:45 PM, Graydon Hoare wrote:
> > There is a specific rule in the C++ specification to address
> > temporaries: they should live up until the end of the full expression
> > they are part of.
>
> If it is difficult to get that working right, would it be easier if they
> lived to the end of the block? That is the effect of naming them, right?
>
> (I always thought C++'s rule was more of a stunt or joke than a useful
> rule---it's apparently harder to get right than I thought it was, it's
> hard to explain to people, and it does nothing useful for me,
> programming-wise.)
>
> It is very hard to get right indeed, especially because expressions can be
nested within themselves and objects should be destroyed in the strict
reverse order they were created. As I said, it regularly generates bugs in
Clang (and I imagine gcc) because each time you introduce a new kind of
node in the AST you need to make sure it plays right with this rule (among
others) and the problem is generally subtle enough to get through the
initial testing phase unnoticed.

On the other hand, with RAII, it can be quite interesting; you can simulate
a "with .... as name:" python statement somewhat for example
"with(...).do([](auto& name) { ... })"

-- Matthieu


> --
> Tommy M. McGuire
> [email protected]
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to