From 3459b51fa2b8d1c119c6e707cb18cb8b41967210 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sun, 19 Mar 2023 12:06:42 +0700 Subject: [PATCH 1/6] Don't warn when using operator<=> with 0 --- stl/inc/compare | 16 ++++++++++++++-- .../tests/P0768R1_spaceship_operator/test.cpp | 4 ++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/stl/inc/compare b/stl/inc/compare index 76723bf8162..ea95daf30f6 100644 --- a/stl/inc/compare +++ b/stl/inc/compare @@ -27,8 +27,20 @@ _STL_DISABLE_CLANG_WARNINGS #undef new _STD_BEGIN -using _Literal_zero = decltype(nullptr); -using _Compare_t = signed char; +struct partial_ordering; +struct weak_ordering; +struct strong_ordering; + +struct _Literal_zero { + + consteval _Literal_zero(int _Zero) noexcept { + _STL_VERIFY(_Zero == 0, "A literal zero is expected"); + } + + template >> + _Literal_zero(_Ty) = delete; +}; +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 }; diff --git a/tests/std/tests/P0768R1_spaceship_operator/test.cpp b/tests/std/tests/P0768R1_spaceship_operator/test.cpp index 33a1218f7d6..e233266f636 100644 --- a/tests/std/tests/P0768R1_spaceship_operator/test.cpp +++ b/tests/std/tests/P0768R1_spaceship_operator/test.cpp @@ -7,6 +7,10 @@ #include #include +#ifdef __clang__ +#pragma clang diagnostic error "-Wzero-as-null-pointer-constant" +#endif // __clang__ + enum class comp { equal, less, greater, unordered }; template From af5ee479f95732311cf460a418c39e07191bbc9d Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sun, 19 Mar 2023 12:40:29 +0700 Subject: [PATCH 2/6] cannnot use _STL_VERIFY --- stl/inc/compare | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stl/inc/compare b/stl/inc/compare index ea95daf30f6..93668d64ccd 100644 --- a/stl/inc/compare +++ b/stl/inc/compare @@ -31,10 +31,15 @@ struct partial_ordering; struct weak_ordering; struct strong_ordering; +void __Literal_zero_is_expected(); + struct _Literal_zero { consteval _Literal_zero(int _Zero) noexcept { - _STL_VERIFY(_Zero == 0, "A literal zero is expected"); + // Can't use _STL_VERIFY because this is a core header + if (_Zero != 0) { + __Literal_zero_is_expected(); + } } template >> From cdba5727b3289e7fd3696a4c4ccd5993fcbbde36 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sun, 19 Mar 2023 12:52:02 +0700 Subject: [PATCH 3/6] remove extra `_` --- stl/inc/compare | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/compare b/stl/inc/compare index 93668d64ccd..881d446d067 100644 --- a/stl/inc/compare +++ b/stl/inc/compare @@ -31,14 +31,14 @@ struct partial_ordering; struct weak_ordering; struct strong_ordering; -void __Literal_zero_is_expected(); +void _Literal_zero_is_expected(); struct _Literal_zero { consteval _Literal_zero(int _Zero) noexcept { // Can't use _STL_VERIFY because this is a core header if (_Zero != 0) { - __Literal_zero_is_expected(); + _Literal_zero_is_expected(); } } From a40d7213913a5b3e82cf906db5076f8389f45720 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Tue, 21 Mar 2023 21:48:20 +0700 Subject: [PATCH 4/6] Code review suggestions Co-authored-by: Stephan T. Lavavej --- stl/inc/compare | 14 ++++++-------- .../std/tests/P0768R1_spaceship_operator/test.cpp | 1 + 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/stl/inc/compare b/stl/inc/compare index 881d446d067..fa2b3ef3583 100644 --- a/stl/inc/compare +++ b/stl/inc/compare @@ -27,24 +27,22 @@ _STL_DISABLE_CLANG_WARNINGS #undef new _STD_BEGIN -struct partial_ordering; -struct weak_ordering; -struct strong_ordering; +_EXPORT_STD struct partial_ordering; +_EXPORT_STD struct weak_ordering; +_EXPORT_STD struct strong_ordering; void _Literal_zero_is_expected(); struct _Literal_zero { - - consteval _Literal_zero(int _Zero) noexcept { + template , 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(); } } - - template >> - _Literal_zero(_Ty) = delete; }; + using _Compare_t = signed char; // These "pretty" enumerator names are safe since they reuse names of user-facing entities. diff --git a/tests/std/tests/P0768R1_spaceship_operator/test.cpp b/tests/std/tests/P0768R1_spaceship_operator/test.cpp index e233266f636..5cf07d2b597 100644 --- a/tests/std/tests/P0768R1_spaceship_operator/test.cpp +++ b/tests/std/tests/P0768R1_spaceship_operator/test.cpp @@ -7,6 +7,7 @@ #include #include +// See https://github.com/microsoft/STL/pull/3581 for details #ifdef __clang__ #pragma clang diagnostic error "-Wzero-as-null-pointer-constant" #endif // __clang__ From e31e48b33f980f95ee2b19423519c4962913aa65 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 21 Mar 2023 17:43:27 -0700 Subject: [PATCH 5/6] Drop unnecessary forward declarations. --- stl/inc/compare | 4 ---- 1 file changed, 4 deletions(-) diff --git a/stl/inc/compare b/stl/inc/compare index fa2b3ef3583..99e4a402cde 100644 --- a/stl/inc/compare +++ b/stl/inc/compare @@ -27,10 +27,6 @@ _STL_DISABLE_CLANG_WARNINGS #undef new _STD_BEGIN -_EXPORT_STD struct partial_ordering; -_EXPORT_STD struct weak_ordering; -_EXPORT_STD struct strong_ordering; - void _Literal_zero_is_expected(); struct _Literal_zero { From cc9f43492d507e26ee09ecaa7493639648504abd Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 21 Mar 2023 17:43:45 -0700 Subject: [PATCH 6/6] Use `GH-` for citation. --- tests/std/tests/P0768R1_spaceship_operator/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P0768R1_spaceship_operator/test.cpp b/tests/std/tests/P0768R1_spaceship_operator/test.cpp index 5cf07d2b597..00cfcc17a5c 100644 --- a/tests/std/tests/P0768R1_spaceship_operator/test.cpp +++ b/tests/std/tests/P0768R1_spaceship_operator/test.cpp @@ -7,7 +7,7 @@ #include #include -// See https://github.com/microsoft/STL/pull/3581 for details +// See GH-3581 for details #ifdef __clang__ #pragma clang diagnostic error "-Wzero-as-null-pointer-constant" #endif // __clang__