g ++警告:永远不会被执行

时间:2013-01-29 20:37:09

标签: c++ gcc-warning gcc4

继承了一个C ++项目。我正在使用gcc 4.1.2通过makefile在RHEL 5.5中构建。该项目是巨大的(数百个文件),一般来说代码非常好。但是,在编译期间,我经常会收到GCC警告:

/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h: In constructor ‘std::allocator<_Alloc>::allocator() [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h:97: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h:97: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h: In constructor ‘__gnu_cxx::new_allocator<_Tp>::new_allocator() [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h:65: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h: In destructor ‘std::allocator<_Alloc>::~allocator() [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h:105: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h: In destructor ‘__gnu_cxx::new_allocator<_Tp>::~new_allocator() [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h:72: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h: In copy constructor ‘std::allocator<_Alloc>::allocator(const std::allocator<_Alloc>&) [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h:100: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h:99: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h: In copy constructor ‘__gnu_cxx::new_allocator<_Tp>::new_allocator(const __gnu_cxx::new_allocator<_Tp>&) [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h:67: warning: will never be executed
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h: In destructor ‘std::allocator<_Alloc>::~allocator() [with _Tp = char]’:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/allocator.h:105: warning: will never be executed

它没有提供错误源自的源文件或行号。我打算走出去,说GCC的标题很好,所以这里发生了什么?我以前从未遇到过这个特别警告。

2 个答案:

答案 0 :(得分:9)

根据http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46158的gcc错误46158,-Wunreachable-code一直被破坏,自gcc-4.5以来已被删除。您的问题很可能实际上不是问题。 (就个人而言,我仍然会考虑使用更新的gcc / g ++,除非有特殊原因使用4.1.2 - 它已有将近6年了。)

答案 1 :(得分:3)

此错误报告http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46158在底部说

  

-Wunreachable-code已损坏,已从GCC 4.5中删除。不要使用它。

所以忽略警告并不是一个完全不好的主意。