diff options
| author | Eric Fiselier <eric@efcs.ca> | 2018-04-06 21:37:23 +0000 |
|---|---|---|
| committer | Eric Fiselier <eric@efcs.ca> | 2018-04-06 21:37:23 +0000 |
| commit | 0913ca197855626c93fdae4184ae80ff5a26503a (patch) | |
| tree | e7765626e6ab2a71e67babcfefd2ab0ecb7758e1 /libcxx/test/std/language.support/cmp/cmp.weakeq/cmp.weakeq.pass.cpp | |
| parent | 66f53d71f7e0ff1c2811ec6741af511c588fd038 (diff) | |
| download | bcm5719-llvm-0913ca197855626c93fdae4184ae80ff5a26503a.tar.gz bcm5719-llvm-0913ca197855626c93fdae4184ae80ff5a26503a.zip | |
Implement P0768r1: Library support for the Spaceship Operator.
this patch adds the <compare> header and implements all of it
except for [comp.alg].
As I understand it, the header is needed by the compiler in
when implementing the semantics of operator<=>. For that reason
I feel it's important to land this header early, despite
all compilers lacking support.
llvm-svn: 329460
Diffstat (limited to 'libcxx/test/std/language.support/cmp/cmp.weakeq/cmp.weakeq.pass.cpp')
| -rw-r--r-- | libcxx/test/std/language.support/cmp/cmp.weakeq/cmp.weakeq.pass.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/libcxx/test/std/language.support/cmp/cmp.weakeq/cmp.weakeq.pass.cpp b/libcxx/test/std/language.support/cmp/cmp.weakeq/cmp.weakeq.pass.cpp new file mode 100644 index 00000000000..375cff460cd --- /dev/null +++ b/libcxx/test/std/language.support/cmp/cmp.weakeq/cmp.weakeq.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// <compare> + +// class weak_equality + + +#include <compare> +#include <cassert> +#include "test_macros.h" + +const volatile void* volatile sink; + +void test_static_members() { + DoNotOptimize(&std::weak_equality::equivalent); + DoNotOptimize(&std::weak_equality::nonequivalent); +} + +void test_signatures() { + auto& Eq = std::weak_equality::equivalent; + + ASSERT_NOEXCEPT(Eq == 0); + ASSERT_NOEXCEPT(0 == Eq); + ASSERT_NOEXCEPT(Eq != 0); + ASSERT_NOEXCEPT(0 != Eq); +#ifndef TEST_HAS_NO_SPACESHIP_OPERATOR + ASSERT_NOEXCEPT(0 <=> Eq); + ASSERT_NOEXCEPT(Eq <=> 0); + ASSERT_SAME_TYPE(decltype(Eq <=> 0), std::weak_equality); + ASSERT_SAME_TYPE(decltype(0 <=> Eq), std::weak_equality); +#endif +} + +constexpr bool test_constexpr() { + auto& Eq = std::weak_equality::equivalent; + auto& NEq = std::weak_equality::nonequivalent; + assert((Eq == 0) == true); + assert((0 == Eq) == true); + assert((NEq == 0) == false); + assert((0 == NEq) == false); + + assert((Eq != 0) == false); + assert((0 != Eq) == false); + assert((NEq != 0) == true); + assert((0 != NEq) == true); + +#ifndef TEST_HAS_NO_SPACESHIP_OPERATOR + std::weak_equality res = (Eq <=> 0); + ((void)res); + res = (0 <=> Eq); + ((void)res); +#endif + + return true; +} + +int main() { + test_static_members(); + test_signatures(); + static_assert(test_constexpr(), "constexpr test failed"); +} |

