在"warning: will never be executed"中使用'g++'结果

Using 'g++' results in "warning: will never be executed"

本文关键字:g++ 结果 executed warning will never be      更新时间:2023-10-16

我继承了一个C++项目。我正在通过生成文件使用 GCC 5.5 在 RHEL 4.1.2 中构建。该项目很大(数百个文件),总的来说代码非常好。但是,在编译过程中,我经常收到一个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]’:
/bits/allocator.h:97: warning: will never be executed
/bits/allocator.h:97: warning: will never be executed
/ext/new_allocator.h: In constructor ‘__gnu_cxx::new_allocator<_Tp>::new_allocator() [with _Tp = char]’:
/ext/new_allocator.h:65: warning: will never be executed
/bits/allocator.h: In destructor ‘std::allocator<_Alloc>::~allocator() [with _Tp = char]’:
/bits/allocator.h:105: warning: will never be executed
/ext/new_allocator.h: In destructor ‘__gnu_cxx::new_allocator<_Tp>::~new_allocator() [with _Tp = char]’:
/ext/new_allocator.h:72: warning: will never be executed
/bits/allocator.h: In copy constructor ‘std::allocator<_Alloc>::allocator(const std::allocator<_Alloc>&) [with _Tp = char]’:
/bits/allocator.h:100: warning: will never be executed
/bits/allocator.h:99: warning: will never be executed
/ext/new_allocator.h: In copy constructor ‘__gnu_cxx::new_allocator<_Tp>::new_allocator(const __gnu_cxx::new_allocator<_Tp>&) [with _Tp = char]’:
/ext/new_allocator.h:67: warning: will never be executed
/bits/allocator.h: In destructor ‘std::allocator<_Alloc>::~allocator() [with _Tp = char]’:
/bits/allocator.h:105: warning: will never be executed

它没有给我错误来源的源文件或行号。我要冒昧地说GCC的标题很好,那么这是怎么回事?我以前从未遇到过这种特殊的警告。

根据 GCC 错误 46158,-Wunreachable-code 一直被破坏,并且自 GCC 4.5 以来已被删除。

很可能你的问题实际上不是问题。(就个人而言,除非有特殊原因使用 4.1.2,否则我仍然会考虑更新的 gcc/g++ - 它已经快 6 年了。

错误报告46158在底部说:

-

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

因此,忽略警告听起来并不是一个完全坏的主意。