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.
This commit is contained in:
Jonathan Wakely 2021-02-03 15:49:36 +00:00
parent 5988765741
commit a6f08be383
5 changed files with 15 additions and 3 deletions

View file

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

View file

@ -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 );
}

View file

@ -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()

View file

@ -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;

View file

@ -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 );