C++ 通用条款第4.8.4节;pragma GCC诊断未应用”字样;

C++ 通用条款第4.8.4节;pragma GCC诊断未应用”字样;,c++,gcc,c-preprocessor,pragma,C++,Gcc,C Preprocessor,Pragma,使用g++(Ubuntu 4.8.4-2ubuntu1~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 如果我调用: ~/Devel/pragma $ gcc -Werror

使用g++(Ubuntu 4.8.4-2ubuntu1~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
如果我调用:

~/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

我在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;
}
...

如果您关闭
-Werror
?这不是该bug线程上链接的另一个SO问题的副本吗?@LightnessRacesinOrbit请注意,我的问题是,“我想知道是否有人可以使用它?”。他也在问关于4.7的问题,我也在问关于4.8.4的问题。此错误可能已解决。请注意,该bug指出它是在4.8.0中出现的。因此,从理论上讲,这是一个后续行动,看看是否有人在4.8.4中解决了问题。@LightnessRacesinOrbit关闭-Werror不处理任何警告,除非我指定的警告。另外,根据gcc的文档,“请注意,这些pragma会覆盖任何命令行选项。”请参见我知道
-Werror
的功能。我在问它对这个bug有什么影响。
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
...
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;
}
...