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

            Bug ID: 15541
           Summary: Wrong behavior with operator new overloading when
                    using O2 for optimization
           Product: clang
           Version: 3.2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified

When having the overloaded new operator defined in other cpp or in a lib, clang
with O2 or above with optimize a new operation without assignment, and it will
not call the overloaded new at all.

This behavior is different when the overloaded new operator is defined in the
same cpp file.

The following code will reproduce the problem.

test.cpp
#include <iostream>

#define CHECK(expect, actual) std::cout << "EXPECT:" << expect <<
"\tACTUAL:"<<actual << std::endl
extern bool newCalled;

void testNewWithoutAssignment() {
    newCalled = false;
    new char;
    CHECK(1, newCalled);
}
char *p;
void testNewWithAssignment() {
    newCalled = false;
    p = new char;
    CHECK(1, newCalled);
}

int main() {
    testNewWithoutAssignment();
    testNewWithAssignment();
    return 0;
}

new.cpp
#include <exception>
#include <new>
#include <cstdlib>

bool newCalled = false;
void* operator new (size_t size)  throw (std::bad_alloc)
{
    newCalled = true;
    return malloc(size);
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to