使用g++ (Ubuntu4.8.4-2 ubuntu1~14.04) 4.8.4
在预编译的标题中,我有以下内容:
63 #pragma GCC diagnostic push
64 #pragma GCC diagnostic ignored "-Wunused-variable"
65 #include <boost/filesystem.hpp>
66 #pragma GCC diagnostic pop现在,当我要运行我们的构建系统时,我会得到以下构建错误:
from <>../../../../Core_Pch.h:65,
from <command-line>:0:
<>/../../../../external/include/BoostBase/boost/system/error_code.hpp: At global scope:
<>/../../../../external/include/BoostBase/boost/system/error_code.hpp:221:36: error: ‘boost::system::posix_category’ defined but not used [-Werror=unused-variable]
static const error_category & posix_category = generic_category();GCC的虫追踪器中似乎已经打开了一个可能的漏洞。不过,我想知道是否有人能做到这一点?该bug没有注意到C lexer使用的预处理器的行为与C++ lexer使用的行为不同。
这可能与我们构建系统中的其他东西有关。请注意,如果我创建最简单的示例:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
int main(void)
{
int x;
return 0;
}
#pragma GCC diagnostic pop如果我调用:
~/Devel/pragma $ gcc -Werror -Wall -pedantic main.c
~/Devel/pragma $ g++ -Werror -Wall -pedantic main.c 将忽略的行注释掉将导致:
mhoggan@mhoggan-Precision-T3600 ~/Devel/pragma $ gcc -Werror -Wall -pedantic main.c
main.c:2:1: error: C++ style comments are not allowed in ISO C90 [-Werror]
//#pragma GCC diagnostic ignored "-Wunused-variable"
^
main.c:2:1: error: (this will be reported only once per input file) [-Werror]
main.c: In function ‘main’:
main.c:5:7: error: unused variable ‘x’ [-Werror=unused-variable]
int x;
^
cc1: all warnings being treated as errors
mhoggan@mhoggan-Precision-T3600 ~/Devel/pragma $ g++ -Werror -Wall -pedantic main.c
main.c: In function ‘int main()’:
main.c:5:7: error: unused variable ‘x’ [-Werror=unused-variable]
int x;
^
cc1plus: all warnings being treated as errors发布于 2018-09-14 05:26:39
我在g++ 5.3.0上也有同样的警告。通过在定义下添加一个虚拟函数,我找到了一个讨厌的解决方案,例如:
...
static const error_category & posix_category = generic_category();
static const error_category & errno_ecat = generic_caregory();
static const error_category & native_ecat = system_category();
inline void dummy()
{
(void) posix_category;
(void) errno_ecat;
(void) native_ecat;
}
...https://stackoverflow.com/questions/32000061
复制相似问题