首页 > 解决方案 > 如何比较系统和通用类别中的 std::error_code?

问题描述

我的印象是,我应该能够以下面的方式比较系统类别和通用类别错误。我错过了什么吗?当我使用 gcc 执行此操作时,它们比较不相等。

#include <iostream>
#include <system_error>

int main()
{
    std::error_code s{ENOSPC, std::system_category()};
    auto g = std::errc::no_space_on_device;
    std::cout << (g == s) << std::endl;
}

标签: c++

解决方案


这是 gcc 中的一个错误。如here所述,它已在最新版本中得到纠正。已在所有活动分支上修复,因此将在 6.5、7.4、8.3 和 9.1 版本中修复。

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60555


推荐阅读