我有下面的代碼:爲什麼g ++不會在啓用`-fpic`的情況下發出這個構造函數相關的noexcept警告?
#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
要使用哪個版本的gcc進行編譯? –
@kumar_m_kiran 4.7.2 – Arseniy