缩短GCC错误消息

Ser*_*eyA 3 c++ gcc

每当gcc找不到具有多个重载的函数的匹配重载时,它就会给出错误的行和行,解释尝试了哪个重载以及为什么不使用它.

虽然它通常是有用的,但它通常也不是,因为问题只是呼叫站点的简单错字.在这种特殊情况下,它甚至没有帮助,因为甚至需要花费相当长的时间来找出哪一行最终导致了这个问题.

是否有任何命令行切换到GCC以缩短输出并且仅包括实际的触发线?例如:

#include <string>
#include <iostream>

struct Z{};

void foo() {

    std::string s;
    Z z;

    std::cout << z; // typo - meant s 
}
Run Code Online (Sandbox Code Playgroud)

请参阅错误输出:https://godbolt.org/g/wz5vL2

小额补充:第三方解决方案(STLFilt,gccfilter等)不适合这项法案,因为a)我的工作环境不欢迎安装第三方应用程序,b)它们往往无法维护并停止使用下一个编译器升级

Nat*_*ica 6

一种方法是使用-Wfatal-errors.它会更改错误消息

<source>: In function 'void foo()':

<source>:11:15: error: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'Z')

     std::cout << z; // typo - meant s

     ~~~~~~~~~~^~~~

In file included from /opt/compiler-explorer/gcc-7.3.0/include/c++/7.3.0/iostream:39:0,

                 from <source>:2:

/opt/compiler-explorer/gcc-7.3.0/include/c++/7.3.0/ostream:108:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]

       operator<<(__ostream_type& (*__pf)(__ostream_type&))

many more lines of errors
Run Code Online (Sandbox Code Playgroud)

    <source>: In function 'void foo()':

<source>:11:15: error: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'Z')

     std::cout << z; // typo - meant s

     ~~~~~~~~~~^~~~

compilation terminated due to -Wfatal-errors.

Compiler returned: 1
Run Code Online (Sandbox Code Playgroud)

唯一的缺点是你只会得到第一个错误.如果您的编译时间很长,那么这不是最好的,因为在修复第一个错误并重新编译之前,您将无法修复任何其他错误.