[LLVMbugs] [Bug 17591] New: diagnose replacement allocation functions that are defined 'inline'

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Oct 15 13:57:53 PDT 2013


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: unassignedclangbugs at nondot.org
          Reporter: richard-llvm at metafoo.co.uk
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu,
                    mclow.lists at gmail.com, rafael.espindola at gmail.com
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20131015/f11000cf/attachment.html>


More information about the llvm-bugs mailing list