Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't warn when using operator<=> with 0 #3581

Merged
merged 6 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 13 additions & 2 deletions stl/inc/compare
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,19 @@ _STL_DISABLE_CLANG_WARNINGS
#undef new

_STD_BEGIN
using _Literal_zero = decltype(nullptr);
using _Compare_t = signed char;
void _Literal_zero_is_expected();

struct _Literal_zero {
template <class _Ty, enable_if_t<is_same_v<_Ty, int>, int> = 0>
consteval _Literal_zero(_Ty _Zero) noexcept {
// Can't use _STL_VERIFY because this is a core header
if (_Zero != 0) {
_Literal_zero_is_expected();
}
}
};

using _Compare_t = signed char;

// These "pretty" enumerator names are safe since they reuse names of user-facing entities.
enum class _Compare_eq : _Compare_t { equal = 0, equivalent = equal };
Expand Down
5 changes: 5 additions & 0 deletions tests/std/tests/P0768R1_spaceship_operator/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
#include <compare>
#include <type_traits>

// See GH-3581 for details
#ifdef __clang__
#pragma clang diagnostic error "-Wzero-as-null-pointer-constant"
#endif // __clang__

enum class comp { equal, less, greater, unordered };

template <comp Z, class T>
Expand Down