Error handling. Mapping system error codes to generic

最后都变了- 提交于 2019-12-10 11:24:29

问题


I've found that function default_error_condition doesn't work as expected in my code

auto ec = std::system_category().default_error_condition(EACCES);
std::cout << ec.value() << std::endl << ec.category().name() << std::endl;

Returned ec value has system error category, but it has to be generic, if I got it right from the documentation e.g. cppreference and gcc source code system_error.cc

UPD: also found this remark in the standard 19.5.1.5 Error category objects

The object’s default_error_condition virtual function shall behave as follows:

If the argument ev corresponds to a POSIX errno value posv, the function shall return error_condition(posv, generic_category()). Otherwise, the function shall return error_condition(ev, system_category())

What is happening here ?

I'm using g++ 7.3.0 on linux


回答1:


You're right that, because of the argument, an error_condition(ev,generic_category()) should be returned from default_error_condition and thus the output should be "generic".

Looking at the "history" of the source you linked to, this was a libstdc++ bug until very recently (just three months ago). It was bug 60555.

Jonathan's concluding comment was:

Fixed on all active branches, so will be fixed in the 6.5, 7.4, 8.3 and 9.1 releases.

So, if you were to upgrade your GCC 7.3 to 7.4 (which doesn't exist yet), you'd see the expected behaviour.



来源:https://stackoverflow.com/questions/53105183/error-handling-mapping-system-error-codes-to-generic

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