Selectively disable GCC warnings for only part of a translation unit(选择性地仅对翻译单元的一部分禁用 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 警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:选择性地仅对翻译单元的一部分禁用 GCC 警告
基础教程推荐
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 从 std::cin 读取密码 2021-01-01