我正在使用gcc编译我的代码,使用-Wall -Wextra -Wpedantic
开关和非扩展标准集(比如它是-std=c++14
)。但是 - 我希望有一个例外并使用__int128
,这会给我一个警告:
warning: ISO C++ does not support ‘__int128’ for ‘hge’ [-Wpedantic]
我可以抑制关于__int128
的具体警告吗?或者,我可以在使用此类型之前和之后临时抑制-Wpedantic
吗?
如果我们咨询documentation for -Wpedantic
,我们可以注意以下事项:
在
__extension__
之后的表达式中也禁用了迂回警告。
一个快速的bit of experimentation表明,这允许人们按预期定义变量,即使在标志下:
__extension__ __int128 hge{};
但是,如果我们打算经常使用这种类型,那当然是相当麻烦的。使其变得难以处理的方法是使用类型别名。虽然我们需要在这里小心,但__extension__
属性必须在整个声明之前:
__extension__ typedef __int128 int128;
你可以看到它工作here。
另一种方法,也就是遵循原始思路的方法,是使用类型别名周围的诊断编译指示:
namespace my_gcc_ints {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
using int128 = __int128;
#pragma GCC diagnostic pop
}
其中还有works rather well。