From a6f08be383f846a0474ea8d1da9222b802c36c7c Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 3 Feb 2021 15:49:36 +0000 Subject: [PATCH] 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_code/operators/three_way.cc: Likewise. * testsuite/19_diagnostics/error_condition/operators/less.cc: Add comment. * testsuite/19_diagnostics/error_condition/operators/three_way.cc: Likewise. --- .../testsuite/19_diagnostics/error_code/operators/less.cc | 5 ++++- .../19_diagnostics/error_code/operators/not_equal.cc | 3 ++- .../19_diagnostics/error_code/operators/three_way.cc | 8 +++++++- .../19_diagnostics/error_condition/operators/less.cc | 1 + .../19_diagnostics/error_condition/operators/three_way.cc | 1 + 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/less.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/less.cc index 655515c4988..abb754136ea 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/less.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/less.cc @@ -29,10 +29,13 @@ int main() VERIFY( !(e1 < e1) ); VERIFY( !(e2 < e2) ); - VERIFY( (e1 < e2) == (e1.value() < e2.value()) ); + 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 a8dfa505dc2..543ffceb832 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 @@ -34,5 +34,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_code/operators/three_way.cc b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/three_way.cc index 448f51d1d73..50c54bea94f 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/three_way.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/error_code/operators/three_way.cc @@ -33,7 +33,7 @@ test01() VERIFY( std::is_neq(e1 <=> e2) ); VERIFY( std::is_lt(e1 <=> e2) || std::is_gt(e1 <=> e2) ); - VERIFY( (e1 <=> e2) == (e1.value() <=> e2.value()) ); + VERIFY( (e1 <=> e2) == (e1.category() <=> e2.category()) ); VERIFY( e1 == e1 ); VERIFY( !(e1 == e2) ); @@ -52,6 +52,12 @@ test01() VERIFY( !(e3 < e3) ); VERIFY( (e2 < e3) == (e2.category() < e3.category()) ); + + std::error_code e4(std::make_error_code(std::errc::invalid_argument)); + + VERIFY( std::is_neq(e4 <=> e2) ); + VERIFY( std::is_lt(e4 <=> e2) || std::is_gt(e4 <=> e2) ); + VERIFY( (e4 <=> e2) == (e4.value() <=> e2.value()) ); } int main() diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/less.cc b/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/less.cc index 96f8b6868af..8a6b71fdc35 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/less.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/less.cc @@ -29,6 +29,7 @@ int main() 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; diff --git a/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/three_way.cc b/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/three_way.cc index 189889706ce..e26afe57366 100644 --- a/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/three_way.cc +++ b/libstdc++-v3/testsuite/19_diagnostics/error_condition/operators/three_way.cc @@ -33,6 +33,7 @@ test01() VERIFY( std::is_neq(e1 <=> e2) ); VERIFY( std::is_lt(e1 <=> e2) || std::is_gt(e1 <=> e2) ); + // e1.category() == e2.category(), so comparison depends on values: VERIFY( (e1 <=> e2) == (e1.value() <=> e2.value()) ); VERIFY( e1 == e1 ); -- 2.30.2