[PATCH] don't store temporary value returned from c_str()

Kim Minh Kaplan kimminh.kaplan+nomuch at afnic.fr
Mon Apr 29 23:12:06 PDT 2013


Vladimir Marek writes:

> Well, a) standards says that
>
> A temporary bound to a reference parameter in a function call (5.2.2)
> persists until the completion of the full expression containing the call
>
> (you can find the message all over the net, but I can't find actual link
> to the standard :-/)

The january 2012 working draft: 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf

    12.2 Temporary objects [class.temporary]

    1 Temporaries of class type are created in various contexts: binding a
    reference to a prvalue (8.5.3), returning a prvalue (6.6.3) […]

    3 When an implementation introduces a temporary object of a class that
    has a non-trivial constructor (12.1, 12.8), it shall ensure that a
    constructor is called for the temporary object. Similarly, the
    destructor shall be called for a temporary with a non-trivial destructor
    (12.4). Temporary objects are destroyed as the last step in evaluating
    the full-expression (1.9) that (lexically) contains the point where they
    were created.

Kim Minh.


More information about the notmuch mailing list