Jon*_*ric 82 c c++ gcc pragma compiler-warnings
与此MSVC预处理器代码最接近的GCC是什么?
#pragma warning( push ) // Save the current warning state.
#pragma warning( disable : 4723 ) // C4723: potential divide by 0
// Code which would generate warning 4723.
#pragma warning( pop ) // Restore warnings to previous state.
Run Code Online (Sandbox Code Playgroud)
我们在常用的标题中包含代码,我们不希望生成特定的警告.但是,我们希望包含这些标头的文件继续生成该警告(如果项目启用了该警告).
Mat*_*ner 93
这可以在GCC自4.6版本开始实施,或者在2010年6月左右在主干中实现.
这是一个例子:
#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wuninitialized"
foo(a); /* error is given for this one */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
foo(b); /* no diagnostic for this one */
#pragma GCC diagnostic pop
foo(c); /* error is given for this one */
#pragma GCC diagnostic pop
foo(d); /* depends on command line options */
Run Code Online (Sandbox Code Playgroud)
cha*_*aos 35
最接近的是GCC编译诊断,#pragma GCC diagnostic [warning|error|ignored] "-Wwhatever".它并不是非常接近你想要的,并查看链接了解详情和警告.
Tom*_*Tom 32
我做了类似的事情.对于第三方代码,我根本不想看到任何警告.所以,而不是指定-I/path/to/libfoo/include,我用过-isystem /path/to/libfoo/include.这使得编译器将这些头文件视为"系统头"以用于警告,并且只要您不启用-Wsystem-headers,您就大多数都是安全的.我仍然看到一些警告泄漏出去,但它减少了大部分垃圾.
请注意,如果您可以通过include-directory隔离有问题的代码,这只会对您有所帮助.如果它只是您自己项目的一个子集,或者与其他代码混合在一起,那么您就不走运了.
| 归档时间: |
|
| 查看次数: |
51518 次 |
| 最近记录: |