I experimented with the overload operators new and delete and noticed that MSVC and GCC seem to be different 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 correctly with GCC (tested with both Ideone online compilers and TutorialsPoint), but not with MSVC (tested with MSVS 2010, MSVS 2015 online and the registry).
While it seems that GCC is compiling it, as you would expect, MSVC emits error C2831 ; I checked Cppreference but could not find an answer; the default parameter on the page does not mention operators, and operator overloading and the operator delete pages do not contain default parameters. Similarly, the Overload of new and delete in the SO C ++ FAQ does not contain default parameters.
So, in light of this, which of these behaviors (allowing default parameters or treating them as an error) conforms to the C ++ standard?
References:
source share