From 6614d36d711495c57d8971f2330065c7cd21b9ef Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Tue, 23 May 2023 15:06:41 +0300 Subject: [PATCH] [libc++][spaceship] Additional tests for `operator<=>` `map` and `multimap` - Added additional tests - Improved existing tests - Moved misplaced test files to the correct location Reviewed By: #libc, philnik Differential Revision: https://reviews.llvm.org/D151205 --- .../{ => map.nonmember}/compare.three_way.pass.cpp | 0 .../map/map.nonmember/compare.three_way.verify.cpp | 61 ++++++++++++ .../compare.three_way.pass.cpp | 0 .../compare.three_way.verify.cpp | 61 ++++++++++++ libcxx/test/support/test_container_comparisons.h | 109 ++++++++++++--------- 5 files changed, 182 insertions(+), 49 deletions(-) rename libcxx/test/std/containers/associative/map/{ => map.nonmember}/compare.three_way.pass.cpp (100%) create mode 100644 libcxx/test/std/containers/associative/map/map.nonmember/compare.three_way.verify.cpp rename libcxx/test/std/containers/associative/multimap/{ => multimap.nonmember}/compare.three_way.pass.cpp (100%) create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.nonmember/compare.three_way.verify.cpp diff --git a/libcxx/test/std/containers/associative/map/compare.three_way.pass.cpp b/libcxx/test/std/containers/associative/map/map.nonmember/compare.three_way.pass.cpp similarity index 100% rename from libcxx/test/std/containers/associative/map/compare.three_way.pass.cpp rename to libcxx/test/std/containers/associative/map/map.nonmember/compare.three_way.pass.cpp diff --git a/libcxx/test/std/containers/associative/map/map.nonmember/compare.three_way.verify.cpp b/libcxx/test/std/containers/associative/map/map.nonmember/compare.three_way.verify.cpp new file mode 100644 index 0000000..a1cd2ab --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.nonmember/compare.three_way.verify.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// class map + +// template +// synth-three-way-result> +// operator<=>(const map& x, +// const map& y); + +#include + +#include "test_allocator.h" + +int main(int, char**) { + // Mismatching allocators + { + std::map, std::allocator> s1; + std::map, test_allocator> s2; + // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed due to requirement 'is_same>::value'{{.*}}Allocator::value_type must be same type as value_type}} + s1 <=> s2; + // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed due to requirement 'is_same>::value'{{.*}}Allocator::value_type must be same type as value_type}} + s2 <=> s1; + } + // Mismatching comparision functions + { + std::map> s1; + std::map> s2; + // expected-error@+1 {{invalid operands to binary expression}} + s1 <=> s2; + // expected-error@+1 {{invalid operands to binary expression}} + s2 <=> s1; + } + { + std::map> s1; + std::map> s2; + // expected-error@+1 {{invalid operands to binary expression}} + s1 <=> s2; + // expected-error@+1 {{invalid operands to binary expression}} + s2 <=> s1; + } + // Mismatching types + { + std::map s1; + std::map s2; + // expected-error@+1 {{invalid operands to binary expression}} + s1 <=> s2; + // expected-error@+1 {{invalid operands to binary expression}} + s2 <=> s1; + } + + return 0; +} diff --git a/libcxx/test/std/containers/associative/multimap/compare.three_way.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.nonmember/compare.three_way.pass.cpp similarity index 100% rename from libcxx/test/std/containers/associative/multimap/compare.three_way.pass.cpp rename to libcxx/test/std/containers/associative/multimap/multimap.nonmember/compare.three_way.pass.cpp diff --git a/libcxx/test/std/containers/associative/multimap/multimap.nonmember/compare.three_way.verify.cpp b/libcxx/test/std/containers/associative/multimap/multimap.nonmember/compare.three_way.verify.cpp new file mode 100644 index 0000000..a6b3a0c --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.nonmember/compare.three_way.verify.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// class multimap + +// template +// synth-three-way-result> +// operator<=>(const multimap& x, +// const multimap& y); + +#include + +#include "test_allocator.h" + +int main(int, char**) { + // Mismatching allocators + { + std::multimap, std::allocator> s1; + std::multimap, test_allocator> s2; + // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed due to requirement 'is_same>::value'{{.*}}Allocator::value_type must be same type as value_type}} + s1 <=> s2; + // expected-error-re@*:* {{{{(static_assert|static assertion)}} failed due to requirement 'is_same>::value'{{.*}}Allocator::value_type must be same type as value_type}} + s2 <=> s1; + } + // Mismatching comparision functions + { + std::multimap> s1; + std::multimap> s2; + // expected-error@+1 {{invalid operands to binary expression}} + s1 <=> s2; + // expected-error@+1 {{invalid operands to binary expression}} + s2 <=> s1; + } + { + std::multimap> s1; + std::multimap> s2; + // expected-error@+1 {{invalid operands to binary expression}} + s1 <=> s2; + // expected-error@+1 {{invalid operands to binary expression}} + s2 <=> s1; + } + // Mismatching types + { + std::multimap s1; + std::multimap s2; + // expected-error@+1 {{invalid operands to binary expression}} + s1 <=> s2; + // expected-error@+1 {{invalid operands to binary expression}} + s2 <=> s1; + } + + return 0; +} diff --git a/libcxx/test/support/test_container_comparisons.h b/libcxx/test/support/test_container_comparisons.h index d3b4033..8748f2d 100644 --- a/libcxx/test/support/test_container_comparisons.h +++ b/libcxx/test/support/test_container_comparisons.h @@ -10,6 +10,7 @@ #ifndef TEST_CONTAINER_COMPARISONS #define TEST_CONTAINER_COMPARISONS +#include #include #include "test_comparisons.h" @@ -84,103 +85,109 @@ constexpr bool test_sequence_container_spaceship() { } // Implementation detail of `test_ordered_map_container_spaceship` -template