Could someone explain to me why this code doesn't compile with g++ version 6.2.0, but compiles fine with clang++ version 3.9.0-svn274438-1 and icpc version 16.0.2
$ cat wtf.cpp
#include <cstdio>
#include <new>
void *operator new(std::size_t) throw(std::bad_alloc);
void *operator new(std::size_t) throw (std::bad_alloc) { void *p; return p; }
$ g++-6 wtf.cpp -c
wtf.cpp: In function ‘void* operator new(std::size_t)’:
wtf.cpp:4:7: error: declaration of ‘void* operator new(std::size_t) throw (std::bad_alloc)’ has a different exception specifier
void *operator new(std::size_t) throw (std::bad_alloc) { void * p; return p; }
^~~~~~~~
wtf.cpp:3:7: note: from previous declaration ‘void* operator new(std::size_t)’
void *operator new(std::size_t) throw(std::bad_alloc);
-std=c++03
, g++ compiles fine. But that doesn't explain why I get this error message, right? Line 3 ofwtf.cpp
still has the same exception specifier as line 4, I think. – Fettle