我有下一个代码:
#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