Skip to content
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1cb1ddd
Spaceship for regex
cbezault Jul 23, 2020
fcb7824
Merge into test from feature/spaceship
cbezault Jul 31, 2020
949fc53
Remove old test files for merge
cbezault Jul 31, 2020
3264617
Don't rely on comparison re-writes
cbezault Jul 31, 2020
ec851f9
Test all the comparison ops. Add back != because of compiler bug
cbezault Aug 4, 2020
00638f6
clang-format
cbezault Aug 4, 2020
f50220b
Fix compilation error in regex spaceship tests.
cbezault Aug 4, 2020
460440f
Resolve Casey's comments
cbezault Aug 6, 2020
ac1a54c
clang format
cbezault Aug 6, 2020
df0cbc3
Fix redefinition of !=
cbezault Aug 7, 2020
4065715
EDG doesn't have iter_value_t yet
cbezault Aug 7, 2020
11f7fb6
Resolve @CaseyCarter's review suggestions
cbezault Aug 10, 2020
8033dc1
Resolve @StephanTLavavej's PR comments
cbezault Aug 18, 2020
66bf777
Don't use _MSC_VER to check for C1XX
cbezault Aug 18, 2020
665e8ad
Fix copy-pasta error
cbezault Aug 19, 2020
0403d0c
initial diagnostics product code
ahanamuk Jul 21, 2020
92149a4
Add diagnostics tests
cbezault Aug 10, 2020
b82c9dc
clang-format
cbezault Aug 10, 2020
df07d1b
Apply suggestions from code review
cbezault Aug 18, 2020
a119d4b
Fix @StephanTLavavej's comment
cbezault Aug 19, 2020
844f5bf
clang-format
cbezault Aug 19, 2020
f6c6797
Revert any extraneous changes to regex
cbezault Aug 20, 2020
c1f031b
Revert any extraneous changes to regex
cbezault Aug 20, 2020
e5f62e7
Merge upstream
cbezault Aug 24, 2020
90b5e4e
Merge branch 'feature/spaceship/diagnostics' of github.com:cbezault/S…
cbezault Aug 24, 2020
5fc389e
Update system_error
cbezault Sep 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 77 additions & 23 deletions stl/inc/system_error
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#include <xerrc.h>
#ifndef _M_CEE_PURE
#include <atomic>
#endif
#include <compare>
#endif // _M_CEE_PURE

#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
Expand Down Expand Up @@ -90,13 +91,22 @@ public:
return _Addr == _Right._Addr;
}

#if !_HAS_CXX20
_NODISCARD bool operator!=(const error_category& _Right) const noexcept {
return !(*this == _Right);
}
#endif // !_HAS_CXX20

// TRANSITION, GH-489
#ifdef __cpp_lib_concepts
_NODISCARD strong_ordering operator<=>(const error_category& _Right) const noexcept {
return compare_three_way{}(_Addr, _Right._Addr);
}
#else // ^^^ defined(__cpp_lib_concepts) / !defined(__cpp_lib_concepts) vvv
_NODISCARD bool operator<(const error_category& _Right) const noexcept {
return _Addr < _Right._Addr;
}
#endif // !defined(__cpp_lib_concepts)

error_category(const error_category&) = delete;
error_category& operator=(const error_category&) = delete;
Expand Down Expand Up @@ -173,6 +183,21 @@ public:
return _System_error_equal(_Left, _Right);
}

// TRANSITION, GH-489
#ifdef __cpp_lib_concepts
_NODISCARD friend strong_ordering operator<=>(const error_code& _Left, const error_code& _Right) noexcept {
if (const auto _Result = _Left.category() <=> _Right.category(); _Result != 0) {
return _Result;
}
return _Left.value() <=> _Right.value();
}
#else // ^^^ defined(__cpp_lib_concepts) / !defined(__cpp_lib_concepts) vvv
_NODISCARD friend bool operator<(const error_code& _Left, const error_code& _Right) noexcept {
return _Left.category() < _Right.category()
|| (_Left.category() == _Right.category() && _Left.value() < _Right.value());
}
#endif // !defined(__cpp_lib_concepts)
#if !_HAS_CXX20
_NODISCARD friend bool operator==(const error_condition& _Left, const error_code& _Right) noexcept {
return _System_error_equal(_Right, _Left);
}
Expand All @@ -188,11 +213,7 @@ public:
_NODISCARD friend bool operator!=(const error_condition& _Left, const error_code& _Right) noexcept {
return !_System_error_equal(_Right, _Left);
}

_NODISCARD friend bool operator<(const error_code& _Left, const error_code& _Right) noexcept {
return _Left.category() < _Right.category()
|| (_Left.category() == _Right.category() && _Left.value() < _Right.value());
}
#endif // !_HAS_CXX20
#endif // _STL_OPTIMIZE_SYSTEM_ERROR_OPERATORS

private:
Expand Down Expand Up @@ -249,22 +270,36 @@ public:
return _Left.category() == _Right.category() && _Left.value() == _Right.value();
}

_NODISCARD friend bool operator!=(const error_condition& _Left, const error_condition& _Right) noexcept {
return !(_Left == _Right);
// TRANSITION, GH-489
#ifdef __cpp_lib_concepts
_NODISCARD friend strong_ordering operator<=>(
const error_condition& _Left, const error_condition& _Right) noexcept {
if (const auto _Result = _Left.category() <=> _Right.category(); _Result != 0) {
return _Result;
}
return _Left.value() <=> _Right.value();
}

#else // ^^^ defined(__cpp_lib_concepts) / !defined(__cpp_lib_concepts) vvv
_NODISCARD friend bool operator<(const error_condition& _Left, const error_condition& _Right) noexcept {
return _Left.category() < _Right.category()
|| (_Left.category() == _Right.category() && _Left.value() < _Right.value());
}
#endif // !defined(__cpp_lib_concepts)
#if !_HAS_CXX20
_NODISCARD friend bool operator!=(const error_condition& _Left, const error_condition& _Right) noexcept {
return !(_Left == _Right);
}
#endif // !_HAS_CXX20

// We grant friendship to the operators from error_code here to allow is_error_code_enum_v but not
// is_error_condition_enum_v enums to be compared directly with error_condition; for example:
// io_errc::stream == make_error_condition(errc::out_of_memory)
friend bool operator==(const error_code& _Left, const error_condition& _Right) noexcept;
#if !_HAS_CXX20
friend bool operator==(const error_condition& _Left, const error_code& _Right) noexcept;
friend bool operator!=(const error_code& _Left, const error_condition& _Right) noexcept;
friend bool operator!=(const error_condition& _Left, const error_code& _Right) noexcept;
#endif // !_HAS_CXX20
#endif // _STL_OPTIMIZE_SYSTEM_ERROR_OPERATORS

private:
Expand All @@ -285,14 +320,42 @@ _NODISCARD inline bool operator==(const error_code& _Left, const error_condition
return _Left.category().equivalent(_Left.value(), _Right) || _Right.category().equivalent(_Left, _Right.value());
}

_NODISCARD inline bool operator==(const error_condition& _Left, const error_code& _Right) noexcept {
return _Right.category().equivalent(_Right.value(), _Left) || _Left.category().equivalent(_Right, _Left.value());
}

_NODISCARD inline bool operator==(const error_condition& _Left, const error_condition& _Right) noexcept {
return _Left.category() == _Right.category() && _Left.value() == _Right.value();
}

// TRANSITION, GH-489
#ifdef __cpp_lib_concepts
_NODISCARD inline strong_ordering operator<=>(const error_code& _Left, const error_code& _Right) noexcept {
if (const auto _Result = _Left.category() <=> _Right.category(); _Result != 0) {
return _Result;
}
return _Left.value() <=> _Right.value();
}

_NODISCARD inline strong_ordering operator<=>(const error_condition& _Left, const error_condition& _Right) noexcept {
if (const auto _Result = _Left.category() <=> _Right.category(); _Result != 0) {
return _Result;
}
return _Left.value() <=> _Right.value();
}
#else // ^^^ defined(__cpp_lib_concepts) / !defined(__cpp_lib_concepts) vvv
_NODISCARD inline bool operator<(const error_code& _Left, const error_code& _Right) noexcept {
return _Left.category() < _Right.category()
|| (_Left.category() == _Right.category() && _Left.value() < _Right.value());
}

_NODISCARD inline bool operator<(const error_condition& _Left, const error_condition& _Right) noexcept {
return _Left.category() < _Right.category()
|| (_Left.category() == _Right.category() && _Left.value() < _Right.value());
}
#endif // !defined(__cpp_lib_concepts)

#if !_HAS_CXX20
_NODISCARD inline bool operator==(const error_condition& _Left, const error_code& _Right) noexcept {
return _Right.category().equivalent(_Right.value(), _Left) || _Left.category().equivalent(_Right, _Left.value());
}

_NODISCARD inline bool operator!=(const error_code& _Left, const error_code& _Right) noexcept {
return !(_Left == _Right);
}
Expand All @@ -308,16 +371,7 @@ _NODISCARD inline bool operator!=(const error_condition& _Left, const error_code
_NODISCARD inline bool operator!=(const error_condition& _Left, const error_condition& _Right) noexcept {
return !(_Left == _Right);
}

_NODISCARD inline bool operator<(const error_code& _Left, const error_code& _Right) noexcept {
return _Left.category() < _Right.category()
|| (_Left.category() == _Right.category() && _Left.value() < _Right.value());
}

_NODISCARD inline bool operator<(const error_condition& _Left, const error_condition& _Right) noexcept {
return _Left.category() < _Right.category()
|| (_Left.category() == _Right.category() && _Left.value() < _Right.value());
}
#endif // !_HAS_CXX20
#endif // _STL_OPTIMIZE_SYSTEM_ERROR_OPERATORS

// VIRTUALS FOR error_category
Expand Down
3 changes: 3 additions & 0 deletions tests/std/tests/P1614R2_spaceship/env.lst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\concepts_matrix.lst
RUNALL_CROSSLIST
PM_CL="/D_STL_OPTIMIZE_SYSTEM_ERROR_OPERATORS=0"
PM_CL="/D_STL_OPTIMIZE_SYSTEM_ERROR_OPERATORS=1"
69 changes: 69 additions & 0 deletions tests/std/tests/P1614R2_spaceship/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <set>
#include <stack>
#include <string>
#include <system_error>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
Expand Down Expand Up @@ -121,6 +122,15 @@ namespace std {
};
} // namespace std

struct dummy_diagnostic : std::error_category {
const char* name() const noexcept override {
return "dummy";
}
std::string message(int) const override {
return "";
}
};

template <class ReturnType, class SmallType, class EqualType, class LargeType>
void spaceship_test(const SmallType& smaller, const EqualType& smaller_equal, const LargeType& larger) {
assert(smaller == smaller_equal);
Expand Down Expand Up @@ -165,6 +175,36 @@ void unordered_containers_test(
assert(something != different);
}

template <class ErrorType>
void diagnostics_test() {
dummy_diagnostic c_mem[2];
{
ErrorType e_smaller(0, c_mem[0]);
ErrorType e_equal(0, c_mem[0]);
ErrorType e_larger(1, c_mem[1]);

spaceship_test<std::strong_ordering>(e_smaller, e_equal, e_larger);
}
{
ErrorType e_smaller(0, c_mem[0]);
ErrorType e_larger(0, c_mem[1]);

assert(e_smaller < e_larger);
assert(!(e_larger < e_smaller));
assert((e_smaller <=> e_larger) < 0);
assert((e_larger <=> e_smaller) > 0);
}
{
ErrorType e_smaller(0, c_mem[0]);
ErrorType e_larger(1, c_mem[0]);

assert(e_smaller < e_larger);
assert(!(e_larger < e_smaller));
assert((e_smaller <=> e_larger) < 0);
assert((e_larger <=> e_smaller) > 0);
}
}

void ordering_test_cases() {
{ // constexpr array
constexpr std::array<int, 5> a0{{2, 8, 9, 1, 9}};
Expand Down Expand Up @@ -412,6 +452,35 @@ void ordering_test_cases() {
static_assert(std::is_same_v<SpaceshipType<WeaklyOrderdByOmissionMatch>, std::weak_ordering>);
static_assert(std::is_same_v<SpaceshipType<PartiallyOrderedMatch>, std::partial_ordering>);
}
{ // Diagnostics Library
diagnostics_test<std::error_code>();
diagnostics_test<std::error_condition>();

dummy_diagnostic c_mem[2];
{
std::error_code e1(0, c_mem[0]);
std::error_condition e2(0, c_mem[0]);

assert(e1 == e2);
assert(e2 == e1);
}
{
std::error_code e1(0, c_mem[0]);
std::error_condition e2(0, c_mem[1]);

assert(e1 != e2);
assert(e2 != e1);
}
{
std::error_code e1(1, c_mem[0]);
std::error_condition e2(0, c_mem[0]);

assert(e1 != e2);
assert(e2 != e1);
}

spaceship_test<std::strong_ordering>(c_mem[0], c_mem[0], c_mem[1]);
}
}

template <class Element, class Ordering>
Expand Down