[libcxx-commits] [PATCH] D146372: [libc++]Don't warn when using operator<=> with 0
Igor Zhukov via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Mar 19 04:32:23 PDT 2023
fsb4000 updated this revision to Diff 506379.
fsb4000 added a comment.
Herald added a subscriber: arichardson.
removed unneeded _LIBCPP_HIDE_FROM_ABI
added __literal_zero_is_expected function for a better error message.
added -Wzero-as-null-pointer-constant warning for all tests
moved cmp/cmp.categories.pre/zero_type.verify.cpp. test to libcxx tests
Also I created the same PR for MSVC STL: https://github.com/microsoft/STL/pull/3581
And GCC failed with this change: "in ‘constexpr’ expansion of ‘f.test_range()::<lambda()>()’ cc1plus: error: taking address of an immediate function ‘consteval std::__1::_CmpUnspecifiedParam::_CmpUnspecifiedParam(int)" (std/algorithms/alg_sorting/alg_min_max/ranges.min.pass.cpp")
I will try to investigate this.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146372/new/
https://reviews.llvm.org/D146372
Files:
libcxx/include/__compare/ordering.h
libcxx/test/libcxx/language.support/cmp/cmp.categories.pre/zero_type.verify.cpp
libcxx/test/std/language.support/cmp/cmp.categories.pre/zero_type.verify.cpp
libcxx/utils/libcxx/test/params.py
Index: libcxx/utils/libcxx/test/params.py
===================================================================
--- libcxx/utils/libcxx/test/params.py
+++ libcxx/utils/libcxx/test/params.py
@@ -18,6 +18,7 @@
'-Wshadow',
'-Wundef',
'-Wunused-template',
+ '-Wzero-as-null-pointer-constant',
'-Wno-unused-command-line-argument',
'-Wno-attributes',
'-Wno-pessimizing-move',
Index: libcxx/test/libcxx/language.support/cmp/cmp.categories.pre/zero_type.verify.cpp
===================================================================
--- libcxx/test/libcxx/language.support/cmp/cmp.categories.pre/zero_type.verify.cpp
+++ libcxx/test/libcxx/language.support/cmp/cmp.categories.pre/zero_type.verify.cpp
@@ -8,10 +8,6 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17
-// In MSVC mode, there's a slightly different number of errors printed for
-// each of these, so it doesn't add up to the exact expected count of 18.
-// XFAIL: msvc
-
// <compare>
// Ensure we reject all cases where an argument other than a literal 0 is used
@@ -23,9 +19,7 @@
void(v op 0L); \
void(0L op v); \
void(v op nullptr); \
- void(nullptr op v); \
- void(v op(1 - 1)); \
- void((1 - 1) op v)
+ void(nullptr op v)
#define TEST_PASS(v, op) \
void(v op 0); \
@@ -33,13 +27,13 @@
template <typename T>
void test_category(T v) {
- TEST_FAIL(v, ==); // expected-error 18 {{}}
- TEST_FAIL(v, !=); // expected-error 18 {{}}
- TEST_FAIL(v, <); // expected-error 18 {{}}
- TEST_FAIL(v, <=); // expected-error 18 {{}}
- TEST_FAIL(v, >); // expected-error 18 {{}}
- TEST_FAIL(v, >=); // expected-error 18 {{}}
- TEST_FAIL(v, <=>); // expected-error 18 {{}}
+ TEST_FAIL(v, ==); // expected-error 12 {{}}
+ TEST_FAIL(v, !=); // expected-error 12 {{}}
+ TEST_FAIL(v, <); // expected-error 12 {{}}
+ TEST_FAIL(v, <=); // expected-error 12 {{}}
+ TEST_FAIL(v, >); // expected-error 12 {{}}
+ TEST_FAIL(v, >=); // expected-error 12 {{}}
+ TEST_FAIL(v, <=>); // expected-error 12 {{}}
TEST_PASS(v, ==);
TEST_PASS(v, !=);
Index: libcxx/include/__compare/ordering.h
===================================================================
--- libcxx/include/__compare/ordering.h
+++ libcxx/include/__compare/ordering.h
@@ -39,9 +39,15 @@
template<class _Tp, class... _Args>
inline constexpr bool __one_of_v = (is_same_v<_Tp, _Args> || ...);
+void __literal_zero_is_expected();
+
struct _CmpUnspecifiedParam {
- _LIBCPP_HIDE_FROM_ABI constexpr
- _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+ consteval
+ _CmpUnspecifiedParam(int __literal_zero) noexcept {
+ if (__literal_zero != 0) {
+ __literal_zero_is_expected();
+ }
+ }
template<class _Tp, class = enable_if_t<!__one_of_v<_Tp, int, partial_ordering, weak_ordering, strong_ordering>>>
_CmpUnspecifiedParam(_Tp) = delete;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146372.506379.patch
Type: text/x-patch
Size: 3259 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230319/74532635/attachment-0001.bin>
More information about the libcxx-commits
mailing list