[LLVMbugs] [Bug 17003] New: Gcc and clang differ in treatment of lifetime-extended temporaries.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Aug 26 09:51:52 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=17003

            Bug ID: 17003
           Summary: Gcc and clang differ in treatment of lifetime-extended
                    temporaries.
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: labath at google.com
                CC: klimek at google.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

int main() {
  struct A {
    A() { printf("%p:  A() \n", (void*)this); }
    ~A() { printf("%p: ~A() \n", (void*)this); }
    A(const A&) = delete;
  };
  const A& a = 1 ? (const A &) A() : (const A &) A();
  printf("Mark \n");
}

When I run the above code compiled with gcc-4.7, the destructor of A is run
after the printf("Mark") line, which means the lifetime of A was indeed
extended. However, clang (trunk) fails to do that (~A() is printed before
Mark).

I am not sure which interpretation is correct, but I am leaning towards gcc
one.

Also, if I remove the explicit const A& cast then clang complains about copy
constructor being deleted, while gcc still lifetime-extends the object (and
does not perform any copy, hopefully).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130826/f68f8b60/attachment.html>


More information about the llvm-bugs mailing list