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 // <array> 10 // UNSUPPORTED: c++03, c++11, c++14 11 // UNSUPPORTED: clang-5, apple-clang-9 12 // UNSUPPORTED: libcpp-no-deduction-guides 13 // Clang 5 will generate bad implicit deduction guides 14 // Specifically, for the copy constructor. 15 16 17 // template <class T, class... U> 18 // array(T, U...) -> array<T, 1 + sizeof...(U)>; 19 // 20 // Requires: (is_same_v<T, U> && ...) is true. Otherwise the program is ill-formed. 21 22 23 #include <array> 24 #include <cassert> 25 #include <cstddef> 26 27 // std::array is explicitly allowed to be initialized with A a = { init-list };. 28 // Disable the missing braces warning for this reason. 29 #include "disable_missing_braces_warning.h" 30 31 #include "test_macros.h" 32 33 constexpr bool tests() 34 { 35 // Test the explicit deduction guides 36 { 37 std::array arr{1,2,3}; // array(T, U...) 38 static_assert(std::is_same_v<decltype(arr), std::array<int, 3>>, ""); 39 assert(arr[0] == 1); 40 assert(arr[1] == 2); 41 assert(arr[2] == 3); 42 } 43 44 { 45 const long l1 = 42; 46 std::array arr{1L, 4L, 9L, l1}; // array(T, U...) 47 static_assert(std::is_same_v<decltype(arr)::value_type, long>, ""); 48 static_assert(arr.size() == 4, ""); 49 assert(arr[0] == 1); 50 assert(arr[1] == 4); 51 assert(arr[2] == 9); 52 assert(arr[3] == l1); 53 } 54 55 // Test the implicit deduction guides 56 { 57 std::array<double, 2> source = {4.0, 5.0}; 58 std::array arr(source); // array(array) 59 static_assert(std::is_same_v<decltype(arr), decltype(source)>, ""); 60 static_assert(std::is_same_v<decltype(arr), std::array<double, 2>>, ""); 61 assert(arr[0] == 4.0); 62 assert(arr[1] == 5.0); 63 } 64 65 return true; 66 } 67 68 int main(int, char**) 69 { 70 tests(); 71 static_assert(tests(), ""); 72 return 0; 73 } 74