【问题标题】:g++ warning: will never be executedg++ 警告:永远不会被执行
【发布时间】:2013-01-29 20:37:09
【问题描述】:

继承了一个 C++ 项目。我正在通过 makefile 使用 gcc 4.1.2 在 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 的标头很好,所以这里发生了什么?我以前从未遇到过这种特别的警告。

【问题讨论】:

  • 离题:谷歌搜索“警告:将永远不会被执行__gnu_cxx::new_allocator”返回此页面作为第二个结果。 抬头
  • @Bribles 并且第一个结果返回一个gcc bug,表示“-Wunreachable-code 已损坏并已从 GCC 4.5 中删除。”。建议从 CXXFLAGS 中删除此警告选项。
  • @harpun 你的 google-fu 很强大!实际上,我并没有将两个和两个放在一起并意识到错误是 CXXFLAG 选项的结果。

标签: c++ gcc-warning gcc4


【解决方案1】:

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

【讨论】:

  • 升级 gcc 在列表中。我认为使用已知的工作配置来设置项目环境是一个很好的第一步。不过,我很想知道我在升级 gcc 时遇到了哪些其他“有趣”的问题。
【解决方案2】:

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

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

所以忽略警告听起来并不是一个完全坏主意。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 2019-12-07
    • 2021-08-19
    • 2016-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多