编译器的标准化程度如何?错误?
我对自动过滤和解释 gcc 和其他编译器输出的错误消息感兴趣
例如这个正则表达式(可以改进,但你明白了)
^(.+?):(\d+)(:(\d+))?:\s+(\w+):\s+(.*)$
会捕获以下 gcc 错误
x.cpp:5:错误:预期的初始化程序位于“std”之前
- $1 = 源名称
$2
= 行号$4
= 列号 (并非所有 gcc 版本)$5
= 类别(“错误”或“警告”)$6
= 错误文本
对于不同版本之间字符串格式的稳定性和可移植性有何保证海湾合作委员会的版本?对其他编译器有什么保证吗?
I am interested in automatically filtering and interpreting the error messages outputted by gcc and other compilers
For example this regex (which could be improved but you get the idea)
^(.+?):(\d+)(:(\d+))?:\s+(\w+):\s+(.*)$
Would capture the following gcc error
x.cpp:5: error: expected initializer before 'std'
with
$1
= name of source$2
= line number$4
= column number (not all gcc versions)$5
= category ("error" or "warning")$6
= error text
What guarantees are made about the stability and portability of the string format between different versions of gcc? Any guarantees for other compilers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有保证 - 标准会说“代码格式错误”,编译器将发出它决定的任何错误。
另外不要忘记,大多数 C++ 编译器甚至不会生成经过优化的错误消息 - 目前没有什么可以标准化的。例如,如果你写:
他们会说
no ; before statements2
这是正确的,但不如no 方便和有用; after statements1
将会是。编译模板时发出的错误消息非常可怕,甚至有独立的美化器。There's no guarantee - the Standard will say "the code is ill-formed" and the compiler will emit whatever error it decides.
Also don't forget that most C++ compiler don't even produce optimally crafted error messages - there's nothing to standardize at the moment. For example, if you write:
they will say
no ; before statement2
which is right, but not as convenient and useful asno ; after statement1
would be. And error messages emitted when compiling templates are so horrible that there're even stand-alone prettifiers for them.