Unexpected exit status when using -pass-exit-codes in g++

这一生的挚爱 提交于 2020-01-16 03:25:48

问题


When doing the following, the exit code of the failed compilation is 1, however, based on this, I would expect it to be >=3. Why is this? What can I do if I want more detailed exit codes than binary success/fail?

> echo "int main() {fail}" > fail.cpp
> g++ -pass-exit-codes fail.cpp -o fail
fail.cpp: In function ‘int main()’:
fail.cpp:1: error: ‘fail’ was not declared in this scope
fail.cpp:1: error: expected ';' before ‘}’ token
> echo $?
1
> g++ --version
g++ (GCC) 4.1.3 20080704 (Red Hat 4.1.2-27)

Thanks.


回答1:


The documentation that you point at belongs to gcc version 3.3.6. However, in version >=4, the documentation for that compiler flag has changed and it now only states:

-pass-exit-codes
Normally the gcc program exits with the code of 1 if any phase of the compiler returns a non-success return code. If you specify -pass-exit-codes, the gcc program instead returns with the numerically highest error produced by any phase returning an error indication. The C, C++, and Fortran front ends return 4 if an internal compiler error is encountered.

Which is a little confusing when reading it. It does not specify the error codes that were well explained in the documentation of 3.x. Then, it is possible that the exit code that you are looking for is not generated any more in version 4.x of gcc/g++.



来源:https://stackoverflow.com/questions/34889522/unexpected-exit-status-when-using-pass-exit-codes-in-g

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!