#include <new>
#include <cstdlib>
class X
{
protected:
static void* operator new(size_t sz);
static void operator delete(void* p) noexcept;
};
class Y : public X { }; // inheritance is ok
class Z { X x; }; // ok
X x1; // ok
int main()
{
X x2; // ok
Y y1; // ok
X* xp = new X; // syntax error
Y* yp = new Y; // syntax error
delete xp; // syntax error
delete yp; // syntax error
};
I2luY2x1ZGUgPG5ldz4KI2luY2x1ZGUgPGNzdGRsaWI+CgpjbGFzcyBYCnsKcHJvdGVjdGVkOgogIHN0YXRpYyB2b2lkKiBvcGVyYXRvciBuZXcoc2l6ZV90IHN6KTsKICBzdGF0aWMgdm9pZCAgb3BlcmF0b3IgZGVsZXRlKHZvaWQqIHApIG5vZXhjZXB0Owp9OwoKY2xhc3MgWSA6IHB1YmxpYyBYIHsgfTsgIC8vIGluaGVyaXRhbmNlIGlzIG9rCmNsYXNzIFogeyBYIHg7IH07ICAgICAgICAvLyBvawoKWCB4MTsgICAgICAgICAgICAgICAgICAgIC8vIG9rCmludCBtYWluKCkKewogIFggeDI7ICAgICAgICAgICAgICAgICAgLy8gb2sKICBZIHkxOyAgICAgICAgICAgICAgICAgIC8vIG9rCiAgWCogeHAgPSBuZXcgWDsgICAgICAgICAvLyBzeW50YXggZXJyb3IKICBZKiB5cCA9IG5ldyBZOyAgICAgICAgIC8vIHN5bnRheCBlcnJvcgoKICBkZWxldGUgeHA7ICAgICAgICAgICAgIC8vIHN5bnRheCBlcnJvcgogIGRlbGV0ZSB5cDsgICAgICAgICAgICAgLy8gc3ludGF4IGVycm9yCn07
prog.cpp: In function ‘int main()’:
prog.cpp:19:15: error: ‘static void* X::operator new(size_t)’ is protected within this context
X* xp = new X; // syntax error
^
prog.cpp:7:16: note: declared protected here
static void* operator new(size_t sz);
^~~~~~~~
prog.cpp:20:15: error: ‘static void* X::operator new(size_t)’ is protected within this context
Y* yp = new Y; // syntax error
^
prog.cpp:7:16: note: declared protected here
static void* operator new(size_t sz);
^~~~~~~~
prog.cpp:22:10: error: ‘static void X::operator delete(void*)’ is protected within this context
delete xp; // syntax error
^~
prog.cpp:8:16: note: declared protected here
static void operator delete(void* p) noexcept;
^~~~~~~~
prog.cpp:22:10: error: ‘static void X::operator delete(void*)’ is protected within this context
delete xp; // syntax error
^~
prog.cpp:8:16: note: declared protected here
static void operator delete(void* p) noexcept;
^~~~~~~~
prog.cpp:23:10: error: ‘static void X::operator delete(void*)’ is protected within this context
delete yp; // syntax error
^~
prog.cpp:8:16: note: declared protected here
static void operator delete(void* p) noexcept;
^~~~~~~~
prog.cpp:23:10: error: ‘static void X::operator delete(void*)’ is protected within this context
delete yp; // syntax error
^~
prog.cpp:8:16: note: declared protected here
static void operator delete(void* p) noexcept;
^~~~~~~~