From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id D23133886C5E; Tue, 20 Apr 2021 18:52:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D23133886C5E MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r9-9368] libstdc++: Fix incorrect test for std::error_code comparisons X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-9 X-Git-Oldrev: 4b4ddaab3f3fbde599531d92c1490258174d461b X-Git-Newrev: 0c988762f2d206f652fbdb6c4950dc481709328b Message-Id: <20210420185213.D23133886C5E@sourceware.org> Date: Tue, 20 Apr 2021 18:52:13 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Apr 2021 18:52:13 -0000 https://gcc.gnu.org/g:0c988762f2d206f652fbdb6c4950dc481709328b commit r9-9368-g0c988762f2d206f652fbdb6c4950dc481709328b Author: Jonathan Wakely 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 +// . + +#include +#include + +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 +// . + +#include +#include + +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()) ); +}