public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r9-9368] libstdc++: Fix incorrect test for std::error_code comparisons
Date: Tue, 20 Apr 2021 18:52:13 +0000 (GMT)	[thread overview]
Message-ID: <20210420185213.D23133886C5E@sourceware.org> (raw)

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()) );
+}


                 reply	other threads:[~2021-04-20 18:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210420185213.D23133886C5E@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).