mógłby ktoś wytłumaczyć mi, dlaczego ten kod nie skompilować z g ++ w wersji 6.2.0, ale kompiluje grzywny z brzękiem ++ Wersja 3.9.0-svn274438-1 i ICPC 16.0.2Different specifier wyjątek z g ++ 6.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);
Dodając '-std = C++ 03', g ++ kompiluje się dobrze. Ale to nie wyjaśnia, dlaczego dostaję ten komunikat o błędzie, prawda? Linia 3 'wtf.cpp' nadal ma ten sam specyfikator wyjątków co linia 4. Myślę, że. – BigDawg
@BigDawg - 'throw()' i 'noexcept' mają podobny efekt, ale' throw (std :: bad_alloc) 'jest całkowicie odmienny od nieokreślania wyrzucanych wyjątków. –