I was experimenting with overloading operators new
and delete
, and noticed that MSVC and GCC appear to differ in their implementation of operator delete
. Consider the following code:
#include <cstddef>
struct CL {
// The bool does nothing, other than making these placement overloads.
void* operator new(size_t s, bool b = true);
void operator delete(void* o, bool b = true);
};
// Functions are simple wrappers for the normal operators.
void* CL::operator new(size_t s, bool b) { return ::operator new(s); }
void CL::operator delete(void* o, bool b) { return ::operator delete(o); }
auto aut = new (false) CL;
This code will compile properly with GCC (tested with both Ideone and TutorialsPoint online compilers), but not with MSVC (tested with MSVS 2010, MSVS 2015 online, and Rextester).
While it appears that GCC compiles it as one would expect, MSVC emits error C2831; I checked Cppreference, but couldn't find an answer; the default parameter page doesn't mention operators, and the operator overloading & operator delete pages don't mention default parameters. Similarly, the Overloading new
and delete
entry in SO's C++ FAQ doesn't mention default parameters.
So, in light of this, which of these behaviours (allowing default parameters, or treating them as an error) is compliant with the C++ standard?
Links: