[libcxx-commits] [libcxx] [libc++] Avoid -Wzero-as-null-pointer-constant in operator<=> (PR #79465)
Richard Smith via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Feb 13 15:04:28 PST 2025
================
@@ -30,14 +30,20 @@ class partial_ordering;
class weak_ordering;
class strong_ordering;
-template <class _Tp, class... _Args>
-inline constexpr bool __one_of_v = (is_same_v<_Tp, _Args> || ...);
-
struct _CmpUnspecifiedParam {
- _LIBCPP_HIDE_FROM_ABI constexpr _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
-
- template <class _Tp, class = enable_if_t<!__one_of_v<_Tp, int, partial_ordering, weak_ordering, strong_ordering>>>
- _CmpUnspecifiedParam(_Tp) = delete;
+ // If anything other than a literal 0 is provided, the behavior is undefined by the Standard.
+ //
+ // The alternative to the `__enable_if__` attribute would be to use the fact that a pointer
+ // can be constructed from literal 0, but this conflicts with `-Wzero-as-null-pointer-constant`.
+ template <class _Tp, class = __enable_if_t<is_same_v<_Tp, int> > >
+ _LIBCPP_HIDE_FROM_ABI consteval _CmpUnspecifiedParam(_Tp __zero) noexcept
----------------
zygoloid wrote:
This appears to have [regressed](https://godbolt.org/z/avGzqofnE) our ability to detect comparisons against a `const int`:
```c++
constexpr int n = 0;
// Used to be rejected, now accepted.
(0 <=> 0) < n;
```
[My suggestion](https://github.com/llvm/llvm-project/issues/43670#issuecomment-981022338) from #43670 avoided this by providing a deleted constructor overload that takes an int lvalue; could we do something similar here?
https://github.com/llvm/llvm-project/pull/79465
More information about the libcxx-commits
mailing list