[LLVMbugs] [Bug 11757] New: Missed copy elision when using operator new

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jan 13 04:03:35 PST 2012


             Bug #: 11757
           Summary: Missed copy elision when using operator new
           Product: clang
           Version: 2.9
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: Mozza314 at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

It seems clang misses the copy elision when an rvalue of some class is used for
copy construction through operator new.

This is demonstrated by the assertion failure of the following code:

#include <cassert>
#include <new>

class CopyCounter
    static int mCount;

    CopyCounter() { }
    CopyCounter(const CopyCounter&) { ++mCount; }

    static int Get() { return mCount; }

int CopyCounter::mCount = 0;

int main()
    CopyCounter* f = new CopyCounter(CopyCounter());
    assert(CopyCounter::Get() == 0);

    delete f;

    return 0;

I have tested this on 2.9 but I expect trunk is also affected because of a
similar problem reported to me by someone using a relatively recent checkout of

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list