我需要强制 gcc 在这段代码上引发异常而不是警告:
#include <stdio.h>
int main()
{
printf ("Decimals: %d \n", 1977123124L);
return 0;
}
现在当我运行命令时:
g++ test.cpp -o test.o
test.cpp 是包含这段代码的文件。
我在输出中挥动警告信息:
test.cpp:6: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long int’
并创建了 test.o 文件。
我想要的是错误信息和编译失败。
是否有一些标志或其他任何东西可以帮助 gcc 为我做这件事?
谢谢 =)
最佳答案
使用开关 -Werror=format
。
更一般地说,每当你有一个你想变成错误的警告时,使用 -Werror=(warning name)
;在极端情况下,-Werror
单独会导致所有 警告变成错误。
关于c++ - 如何使 g++ 导致异常而不是警告格式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25329931/