summaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2021-09-22 11:58:20 +0100
committerJonathan Wakely <jwakely@redhat.com>2021-10-13 20:42:08 +0100
commitb90b39a33154949979def3117ca868950ce8025c (patch)
tree6aca48f297e68ac3393d5c8980320196ba9bfefe /libstdc++-v3
parent780aba4a149b3f17a4cee7bf8cc42d1b8a79ec91 (diff)
downloadgcc-b90b39a33154949979def3117ca868950ce8025c.tar.gz
libstdc++: std::system_category should know meaning of zero [PR102425]
Although 0 is not an errno value, it should still be recognized as corresponding to a value belonging to the generic_category(). Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: PR libstdc++/102425 * src/c++11/system_error.cc (system_error_category::default_error_condition): Add 0 to switch. * testsuite/19_diagnostics/error_category/102425.cc: New test. (cherry picked from commit ce01e2e64c340dadb55a8a24c545a13e654804d4)
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/src/c++11/system_error.cc3
-rw-r--r--libstdc++-v3/testsuite/19_diagnostics/error_category/102425.cc18
2 files changed, 21 insertions, 0 deletions
diff --git a/libstdc++-v3/src/c++11/system_error.cc b/libstdc++-v3/src/c++11/system_error.cc
index d67e3a4f975..3c8f32d8eab 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].
@@ -309,6 +311,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 00000000000..069b5e284e1
--- /dev/null
+++ b/libstdc++-v3/testsuite/19_diagnostics/error_category/102425.cc
@@ -0,0 +1,18 @@
+// { dg-do run { target c++11 } }
+#include <system_error>
+#include <testsuite_hooks.h>
+
+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();
+}