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