diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -847,6 +847,12 @@ # define _LIBCPP_CONSTEXPR constexpr #endif +#ifndef __cpp_consteval +# define _LIBCPP_CONSTEVAL _LIBCPP_CONSTEXPR +#else +# define _LIBCPP_CONSTEVAL consteval +#endif + #ifdef _LIBCPP_CXX03_LANG # define _LIBCPP_DEFAULT {} #else diff --git a/libcxx/include/compare b/libcxx/include/compare --- a/libcxx/include/compare +++ b/libcxx/include/compare @@ -154,8 +154,13 @@ __unordered = -127 }; -struct _CmpUnspecifiedType; -using _CmpUnspecifiedParam = void (_CmpUnspecifiedType::*)(); +struct _CmpUnspecifiedParam { + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEVAL + _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) {} + + template>> + _CmpUnspecifiedParam(_Tp) = delete; +}; class weak_equality { _LIBCPP_INLINE_VISIBILITY diff --git a/libcxx/test/std/language.support/cmp/cmp.categories.pre/zero_type.fail.cpp b/libcxx/test/std/language.support/cmp/cmp.categories.pre/zero_type.fail.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/language.support/cmp/cmp.categories.pre/zero_type.fail.cpp @@ -0,0 +1,43 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// Ensure we reject all cases where an argument other than a literal 0 is used +// for a comparison against a comparison category type. + +#include + +#define TEST_OP(op) \ + 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); + +template +void test_category(T v) { + TEST_OP(==); // expected-error 18 {{}} + TEST_OP(!=); // expected-error 18 {{}} + TEST_OP(<); // expected-error 18 {{}} + TEST_OP(<=); // expected-error 18 {{}} + TEST_OP(>); // expected-error 18 {{}} + TEST_OP(>=); // expected-error 18 {{}} + TEST_OP(<=>); // expected-error 18 {{}} +} + +int main(int, char**) { + test_category(std::strong_ordering::equivalent); + test_category(std::weak_ordering::equivalent); + test_category(std::partial_ordering::equivalent); + return 0; +}