diff --git a/libstdc++-v3/src/c++11/system_error.cc b/libstdc++-v3/src/c++11/system_error.cc index f12290adaeea..6c79202eb0ee 100644 --- a/libstdc++-v3/src/c++11/system_error.cc +++ b/libstdc++-v3/src/c++11/system_error.cc @@ -70,6 +70,8 @@ namespace virtual std::error_condition default_error_condition(int ev) const noexcept { + // Use generic category for all known POSIX errno values (including zero) + // and system category otherwise. switch (ev) { // List of errno macros from [cerrno.syn]. @@ -310,6 +312,7 @@ namespace #ifdef EXDEV case EXDEV: #endif + case 0: return std::error_condition(ev, std::generic_category()); /* Additional system-dependent mappings from non-standard error codes diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_category/102425.cc b/libstdc++-v3/testsuite/19_diagnostics/error_category/102425.cc new file mode 100644 index 000000000000..069b5e284e1c --- /dev/null +++ b/libstdc++-v3/testsuite/19_diagnostics/error_category/102425.cc @@ -0,0 +1,18 @@ +// { dg-do run { target c++11 } } +#include +#include + +void test01() +{ + // PR libstdc++/102425 + VERIFY( std::error_code() == std::error_condition() ); + + auto zero = std::system_category().default_error_condition(0); + // This is the condition that the equality above relies on: + VERIFY( zero.category() == std::generic_category() ); +} + +int main() +{ + test01(); +}