【发布时间】:2016-08-28 07:23:21
【问题描述】:
有人能解释一下为什么这段代码不能用 g++ 6.2.0 版编译,但用 clang++ 3.9.0-svn274438-1 和 icpc 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);
【问题讨论】: