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 // UNSUPPORTED: libcpp-has-no-incomplete-ranges 11 12 // clang-cl and cl currently don't support [[no_unique_address]] 13 // XFAIL: msvc 14 15 // [algorithms.results]/1 16 // Each of the class templates specified in this subclause has the template parameters, 17 // data members, and special members specified below, and has no base classes or members 18 // other than those specified. 19 20 #include <algorithm> 21 22 #include "test_macros.h" 23 24 struct Empty {}; 25 struct Empty2 {}; 26 27 static_assert(sizeof(std::ranges::in_fun_result<Empty, int>) == sizeof(int)); 28 static_assert(sizeof(std::ranges::in_fun_result<int, Empty>) == sizeof(int)); 29 static_assert(sizeof(std::ranges::in_fun_result<Empty, Empty>) == 2); 30 31 static_assert(sizeof(std::ranges::in_in_result<Empty, int>) == sizeof(int)); 32 static_assert(sizeof(std::ranges::in_in_result<int, Empty>) == sizeof(int)); 33 static_assert(sizeof(std::ranges::in_in_result<Empty, Empty>) == 2); 34 35 static_assert(sizeof(std::ranges::in_out_result<Empty, int>) == sizeof(int)); 36 static_assert(sizeof(std::ranges::in_out_result<int, Empty>) == sizeof(int)); 37 static_assert(sizeof(std::ranges::in_out_result<Empty, Empty2>) == sizeof(char)); 38 39 static_assert(sizeof(std::ranges::in_in_out_result<Empty, int, int>) == 2 * sizeof(int)); 40 static_assert(sizeof(std::ranges::in_in_out_result<int, Empty, int>) == 2 * sizeof(int)); 41 static_assert(sizeof(std::ranges::in_in_out_result<int, int, Empty>) == 2 * sizeof(int)); 42 static_assert(sizeof(std::ranges::in_in_out_result<char, Empty, Empty>) == 2); 43 static_assert(sizeof(std::ranges::in_in_out_result<Empty, char, Empty>) == 2); 44 static_assert(sizeof(std::ranges::in_in_out_result<Empty, Empty, char>) == 2); 45 static_assert(sizeof(std::ranges::in_in_out_result<int, Empty, Empty2>) == sizeof(int)); 46 static_assert(sizeof(std::ranges::in_in_out_result<Empty, Empty, Empty>) == 3); 47 48 static_assert(sizeof(std::ranges::in_out_out_result<Empty, int, int>) == 2 * sizeof(int)); 49 static_assert(sizeof(std::ranges::in_out_out_result<int, Empty, int>) == 2 * sizeof(int)); 50 static_assert(sizeof(std::ranges::in_out_out_result<int, int, Empty>) == 2 * sizeof(int)); 51 static_assert(sizeof(std::ranges::in_out_out_result<char, Empty, Empty>) == 2); 52 static_assert(sizeof(std::ranges::in_out_out_result<Empty, char, Empty>) == 2); 53 static_assert(sizeof(std::ranges::in_out_out_result<Empty, Empty, char>) == 2); 54 static_assert(sizeof(std::ranges::in_out_out_result<int, Empty, Empty2>) == sizeof(int)); 55 static_assert(sizeof(std::ranges::in_out_out_result<Empty, Empty, Empty>) == 3); 56 57 // In min_max_result both elements have the same type, so they can't have the same address. 58 // So the only way to test that [[no_unique_address]] is used is to have it in another struct 59 struct MinMaxNoUniqueAddress { 60 int a; 61 TEST_NO_UNIQUE_ADDRESS std::ranges::min_max_result<Empty> b; 62 int c; 63 }; 64 65 static_assert(sizeof(std::ranges::min_max_result<Empty>) == 2); 66 static_assert(sizeof(MinMaxNoUniqueAddress) == 8); 67 68 static_assert(sizeof(std::ranges::in_found_result<Empty>) == sizeof(bool)); 69