| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 10 |
|
| 11 |
// clang-cl and cl currently don't support [[no_unique_address]] |
| 12 |
// XFAIL: msvc |
| 13 |
|
| 14 |
// [algorithms.results]/1 |
| 15 |
// Each of the class templates specified in this subclause has the template parameters, |
| 16 |
// data members, and special members specified below, and has no base classes or members |
| 17 |
// other than those specified. |
| 18 |
|
| 19 |
#include <algorithm> |
| 20 |
|
| 21 |
#include "test_macros.h" |
| 22 |
|
| 23 |
struct Empty {}; |
| 24 |
struct Empty2 {}; |
| 25 |
|
| 26 |
static_assert(sizeof(std::ranges::in_fun_result<Empty, int>) == sizeof(int)); |
| 27 |
static_assert(sizeof(std::ranges::in_fun_result<int, Empty>) == sizeof(int)); |
| 28 |
static_assert(sizeof(std::ranges::in_fun_result<Empty, Empty>) == 2); |
| 29 |
|
| 30 |
static_assert(sizeof(std::ranges::in_in_result<Empty, int>) == sizeof(int)); |
| 31 |
static_assert(sizeof(std::ranges::in_in_result<int, Empty>) == sizeof(int)); |
| 32 |
static_assert(sizeof(std::ranges::in_in_result<Empty, Empty>) == 2); |
| 33 |
|
| 34 |
static_assert(sizeof(std::ranges::in_out_result<Empty, int>) == sizeof(int)); |
| 35 |
static_assert(sizeof(std::ranges::in_out_result<int, Empty>) == sizeof(int)); |
| 36 |
static_assert(sizeof(std::ranges::in_out_result<Empty, Empty2>) == sizeof(char)); |
| 37 |
|
| 38 |
static_assert(sizeof(std::ranges::in_in_out_result<Empty, int, int>) == 2 * sizeof(int)); |
| 39 |
static_assert(sizeof(std::ranges::in_in_out_result<int, Empty, int>) == 2 * sizeof(int)); |
| 40 |
static_assert(sizeof(std::ranges::in_in_out_result<int, int, Empty>) == 2 * sizeof(int)); |
| 41 |
static_assert(sizeof(std::ranges::in_in_out_result<char, Empty, Empty>) == 2); |
| 42 |
static_assert(sizeof(std::ranges::in_in_out_result<Empty, char, Empty>) == 2); |
| 43 |
static_assert(sizeof(std::ranges::in_in_out_result<Empty, Empty, char>) == 2); |
| 44 |
static_assert(sizeof(std::ranges::in_in_out_result<int, Empty, Empty2>) == sizeof(int)); |
| 45 |
static_assert(sizeof(std::ranges::in_in_out_result<Empty, Empty, Empty>) == 3); |
| 46 |
|
| 47 |
static_assert(sizeof(std::ranges::in_out_out_result<Empty, int, int>) == 2 * sizeof(int)); |
| 48 |
static_assert(sizeof(std::ranges::in_out_out_result<int, Empty, int>) == 2 * sizeof(int)); |
| 49 |
static_assert(sizeof(std::ranges::in_out_out_result<int, int, Empty>) == 2 * sizeof(int)); |
| 50 |
static_assert(sizeof(std::ranges::in_out_out_result<char, Empty, Empty>) == 2); |
| 51 |
static_assert(sizeof(std::ranges::in_out_out_result<Empty, char, Empty>) == 2); |
| 52 |
static_assert(sizeof(std::ranges::in_out_out_result<Empty, Empty, char>) == 2); |
| 53 |
static_assert(sizeof(std::ranges::in_out_out_result<int, Empty, Empty2>) == sizeof(int)); |
| 54 |
static_assert(sizeof(std::ranges::in_out_out_result<Empty, Empty, Empty>) == 3); |
| 55 |
|
| 56 |
#if TEST_STD_VER >= 23 |
| 57 |
|
| 58 |
static_assert(sizeof(std::ranges::in_value_result<Empty, int>) == sizeof(int)); |
| 59 |
static_assert(sizeof(std::ranges::in_value_result<int, Empty>) == sizeof(int)); |
| 60 |
static_assert(sizeof(std::ranges::in_value_result<Empty, Empty2>) == sizeof(Empty2)); |
| 61 |
|
| 62 |
#endif // TEST_STD_VER |
| 63 |
|
| 64 |
// In min_max_result both elements have the same type, so they can't have the same address. |
| 65 |
// So the only way to test that [[no_unique_address]] is used is to have it in another struct |
| 66 |
struct MinMaxNoUniqueAddress { |
| 67 |
int a; |
| 68 |
TEST_NO_UNIQUE_ADDRESS std::ranges::min_max_result<Empty> b; |
| 69 |
int c; |
| 70 |
}; |
| 71 |
|
| 72 |
static_assert(sizeof(std::ranges::min_max_result<Empty>) == 2); |
| 73 |
static_assert(sizeof(MinMaxNoUniqueAddress) == 8); |
| 74 |
|
| 75 |
static_assert(sizeof(std::ranges::in_found_result<Empty>) == sizeof(bool)); |