选择性地仅对翻译单元的一部分禁用 GCC 警告 [英] Selectively disable GCC warnings for only part of a translation unit

查看:36
本文介绍了选择性地仅对翻译单元的一部分禁用 GCC 警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与此 MSVC 预处理器代码最接近的 GCC 是什么?>

What's the closest GCC equivalent to this MSVC preprocessor code?

#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.

我们在通常包含的标头中有代码,我们不想为其生成特定警告.但是,我们希望包含这些标头的文件继续生成该警告(如果项目启用了该警告).

We have code in commonly included headers which we do not want to generate a specific warning for. However, we want files which include those headers to continue to generate that warning (if the project has that warning enabled).

推荐答案

这是 自 4.6 版起可在 GCC 中,或在 2010 年 6 月左右在主干中.

This is possible in GCC since version 4.6, or around June 2010 in the trunk.

这是一个例子:

#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 */

这篇关于选择性地仅对翻译单元的一部分禁用 GCC 警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆