[gcc r9-9368] libstdc++: Fix incorrect test for std::error_code comparisons

Jonathan Wakely redi@gcc.gnu.org
Tue Apr 20 18:52:13 GMT 2021


https://gcc.gnu.org/g:0c988762f2d206f652fbdb6c4950dc481709328b

commit r9-9368-g0c988762f2d206f652fbdb6c4950dc481709328b
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Feb 3 15:49:36 2021 +0000

    libstdc++: Fix incorrect test for std::error_code comparisons
    
    The tests for std::error_code comparisons assumed that a default
    constructed object uses std::generic_category(). That's true for a
    default constructed std::error_condition, but not std::error_code.
    
    Fix the three-way comparisons to correctly depend on the result of
    comparing the categories, and add another test for comparing two objects
    with the same category and different values.
    
    libstdc++-v3/ChangeLog:
    
            * testsuite/19_diagnostics/error_code/operators/not_equal.cc:
            Add comparison with same category and different values.
            * testsuite/19_diagnostics/error_code/operators/less.cc:
            Likewise. Fix comparison involving different categories.
            * testsuite/19_diagnostics/error_condition/operators/less.cc:
            Add comment.
    
    (cherry picked from commit a6f08be383f846a0474ea8d1da9222b802c36c7c)

Diff:
---
 .../19_diagnostics/error_code/operators/less.cc    | 41 ++++++++++++++++++++++
 .../error_code/operators/not_equal.cc              |  3 +-
 .../error_condition/operators/less.cc              | 39 ++++++++++++++++++++
 3 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/less.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/less.cc
new file mode 100644
index 00000000000..87962ff8991
--- /dev/null
+++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/less.cc
@@ -0,0 +1,41 @@
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-static-libstdc++" { target *-*-mingw* } }
+
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <system_error>
+#include <testsuite_error.h>
+
+int main()
+{
+  std::error_code e1;
+  std::error_code e2(std::make_error_code(std::errc::operation_not_supported));
+
+  VERIFY( !(e1 < e1) );
+  VERIFY( !(e2 < e2) );
+
+  VERIFY( (e1 < e2) == (e1.category() < e2.category()) );
+
+  const __gnu_test::test_category cat;
+  std::error_code e3(e2.value(), cat);
+  VERIFY( !(e3 < e3) );
+  VERIFY( (e2 < e3) == (e2.category() < e3.category()) );
+
+  std::error_code e4(std::make_error_code(std::errc::invalid_argument));
+  VERIFY( (e4 < e2) == (e4.value() < e2.value()) );
+}
diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/not_equal.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/not_equal.cc
index c786771dc18..6d232267e49 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/not_equal.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/not_equal.cc
@@ -35,5 +35,6 @@ int main()
   std::error_code e3(e2.value(), cat);
   VERIFY( e2 != e3 );
 
-  return 0;
+  std::error_code e4(std::make_error_code(std::errc::invalid_argument));
+  VERIFY( e4 != e2 );
 }
diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/less.cc b/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/less.cc
new file mode 100644
index 00000000000..78b4f99f9ec
--- /dev/null
+++ b/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/less.cc
@@ -0,0 +1,39 @@
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-static-libstdc++" { target *-*-mingw* } }
+
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <system_error>
+#include <testsuite_error.h>
+
+int main()
+{
+  std::error_condition e1;
+  std::error_condition e2(std::errc::operation_not_supported);
+
+  VERIFY( !(e1 < e1) );
+  VERIFY( !(e2 < e2) );
+
+  // e1.category() == e2.category(), so comparison depends on values:
+  VERIFY( (e1 < e2) == (e1.value() < e2.value()) );
+
+  const __gnu_test::test_category cat;
+  std::error_condition e3(e2.value(), cat);
+  VERIFY( !(e3 < e3) );
+  VERIFY( (e2 < e3) == (e2.category() < e3.category()) );
+}


More information about the Libstdc++-cvs mailing list