为什么 -Wfatal-errors 会关闭有关错误的注释,以及如何重新打开注释?
Why does -Wfatal-errors turn off notes about the error, and how do I turn notes back on?
我经常使用 -Wfatal-errors
进行构建,因为我不需要额外的 100 个无意义的错误,而编译器会在拼写错误后英勇地尝试解析源文件的其余部分。
但是,我注意到这也会关闭有关致命错误本身的诊断说明。例如,使用 -Wfatal-errors
我会得到,比方说,
main.cpp:10:2: error: invalid new-expression of abstract class type 'C'
new C();
而如果我没有打开 -Wfatal-errors
,我会收到一条提示,告诉我我忘记实现了哪个虚拟方法:
class.hpp:15:2 note: because the following virtual functions are pure within 'C':
class.hpp:28:6 void C::f()
我能否取回这些注释,同时仍保持我在一次错误后终止的行为?
您正在寻找 -fmax-errors=1
。这将在第一个错误后终止编译,但仍会显示该错误的注释。
这里有一个demo来比较这些标志的效果。
我经常使用 -Wfatal-errors
进行构建,因为我不需要额外的 100 个无意义的错误,而编译器会在拼写错误后英勇地尝试解析源文件的其余部分。
但是,我注意到这也会关闭有关致命错误本身的诊断说明。例如,使用 -Wfatal-errors
我会得到,比方说,
main.cpp:10:2: error: invalid new-expression of abstract class type 'C'
new C();
而如果我没有打开 -Wfatal-errors
,我会收到一条提示,告诉我我忘记实现了哪个虚拟方法:
class.hpp:15:2 note: because the following virtual functions are pure within 'C':
class.hpp:28:6 void C::f()
我能否取回这些注释,同时仍保持我在一次错误后终止的行为?
您正在寻找 -fmax-errors=1
。这将在第一个错误后终止编译,但仍会显示该错误的注释。
这里有一个demo来比较这些标志的效果。