[cfe-dev] lifetime of conditional temporaries

Victor Zverovich victor.zverovich at googlemail.com
Tue Nov 17 04:44:38 PST 2009


Dear all

I have found out that in clang conditional temporaries are destroyed not at
the end of the full expression as in gcc but apparently at the end of the
conditional branch.

For example, consider the program below:

#include <stdio.h>

struct S
{
    int i;
    S() { puts("S"); }
    ~S() { puts("~S"); }
};

void f(int) { puts("f"); }

volatile bool b = true;

int main()
{
    f(b ? S().i : 0);
}

If it is compiled with gcc and run the output is:
S
f
~S

With clang the output is:
S
~S
f

The same applies to && and || operators. Is this intended or needs to be
fixed in clang?
In the latter case and if nobody is already working on it I can try fixing
it.

Best regards,
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20091117/693b858c/attachment.html>


More information about the cfe-dev mailing list