问题描述
我发现函数 default_error_condition 不能按我的代码预期的那样工作
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;
返回的 ec 值具有 system 错误类别,但具有如果我从文档中得到正确的答案,请成为通用 和gcc源代码
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:也在标准 19.5.1.5错误类别对象
如果参数ev对应于POSIX errno值posv,则函数应返回error_condition(posv,generic_category())。否则,该函数应返回error_condition(ev,system_category())
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())
这是怎么回事?
I在Linux上使用g ++ 7.3.0
I'm using g++ 7.3.0 on linux
推荐答案
由于参数的原因,您说对了, error_condition(ev,generic_category())
应该从 default_error_condition
返回,因此输出应为 generic
。
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.
乔纳森的结论是:
因此,如果要将GCC 7.3升级到7.4(尚不存在),则d查看预期的行为。
So, if you were to upgrade your GCC 7.3 to 7.4 (which doesn't exist yet), you'd see the expected behaviour.
这篇关于错误处理。将系统错误代码映射到通用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!