How standardised are compilers' errors?
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" o开发者_C百科r "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?
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:
statement1 //no ;
statement2;
they will say no ; before statement2
which is right, but not as convenient and useful as no ; after statement1
would be. And error messages emitted when compiling templates are so horrible that there're even stand-alone prettifiers for them.
精彩评论