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

            Bug ID: 17591
           Summary: diagnose replacement allocation functions that are
                    defined 'inline'
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]
    Classification: Unclassified

17.6.4.6/3 says: The program’s definitions shall not be specified as inline. No
diagnostic is required.

We should diagnose this rule, since it is easy to do so, and violations of it
lead to very odd behavior. Example:

#include <cstdlib>
#include <cstdio>
#include <thread>
#include <unistd.h>

inline void* operator new(size_t size) throw (std::bad_alloc) {
    void* p = malloc(size);
    printf("malloc %zu (%p)\n", size, p);

    return p;
}

inline void operator delete(void* p) throw() {
    printf("free %p\n", p);

    free(p);
}

int main()
{
    std::thread t([] {
        std::this_thread::sleep_for(std::chrono::seconds(1));
    });
    t.detach();

    std::this_thread::sleep_for(std::chrono::seconds(2));
    return 0;
}


When built with optimizations, this gives different numbers of 'malloc' and
'free' lines.

-- 
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