次のコードがあります:
#include <exception>
#include <cstdlib>
void g() { throw 1; }
void (*p)() = g;
template <class T>
void f(T) noexcept (noexcept (T())) // warning 1
{
p();
}
struct A { A() { } }; // warning 2
int main()
{
try { f(A()); } catch (int) { }
return 1;
}
次のオプションを使用すると、
-fno-pic -fmessage-length=0 -std=c++0x -Wnoexcept
g++ は次の警告をスロー します。
noexcept03.C:16:6: warning: noexcept-expression evaluates to 'false' because of a call to 'A::A()' [-Wnoexcept]
noexcept03.C:21:12: warning: but 'A::A()' does not throw; perhaps it should be declared 'noexcept' [-Wnoexcept]
しかし、-fpic
代わりに使用すると-fno-pic
g++
警告がスローされないのはなぜですか?
編集:
GCC バージョン - 4.7.2