Skip to content

Example from cppreference compiles on godbolt, doesn't compile in insights #333

@NooneAtAll

Description

@NooneAtAll

Example from https://en.cppreference.com/w/cpp/memory/new/operator_delete
On godbolt: https://godbolt.org/z/cn1K68
On cppinsights: https://cppinsights.io/s/d7c759a7

#include <cstdio>
#include <cstdlib>
// replacement of a minimal set of functions:
void* operator new(std::size_t sz) {
    std::printf("global op new called, size = %zu\n",sz);
    return std::malloc(sz);
}
void operator delete(void* ptr) noexcept
{
    std::puts("global op delete called");
    std::free(ptr);
}
int main() {
     int* p1 = new int;
     delete p1;
 
     int* p2 = new int[10]; // guaranteed to call the replacement in C++11
     delete[] p2;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions