15a83710eSEric Fiselier //===----------------------------------------------------------------------===// 25a83710eSEric Fiselier // 357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65a83710eSEric Fiselier // 75a83710eSEric Fiselier //===----------------------------------------------------------------------===// 85a83710eSEric Fiselier 95a83710eSEric Fiselier // <array> 105a83710eSEric Fiselier 115a83710eSEric Fiselier // T *data(); 125a83710eSEric Fiselier 135a83710eSEric Fiselier #include <array> 145a83710eSEric Fiselier #include <cassert> 15c019b30aSLouis Dionne #include <cstddef> // for std::max_align_t 16c019b30aSLouis Dionne 1759cdf90aSEric Fiselier #include "test_macros.h" 185a83710eSEric Fiselier 19b4e2e7a2SEric Fiselier // std::array is explicitly allowed to be initialized with A a = { init-list };. 20b4e2e7a2SEric Fiselier // Disable the missing braces warning for this reason. 21b4e2e7a2SEric Fiselier #include "disable_missing_braces_warning.h" 222decfad7SEric Fiselier 23db49965aSMarshall Clow struct NoDefault { 24db49965aSMarshall Clow NoDefault(int) {} 25db49965aSMarshall Clow }; 26db49965aSMarshall Clow 27db49965aSMarshall Clow 28*2df59c50SJF Bastien int main(int, char**) 295a83710eSEric Fiselier { 305a83710eSEric Fiselier { 315a83710eSEric Fiselier typedef double T; 325a83710eSEric Fiselier typedef std::array<T, 3> C; 335a83710eSEric Fiselier C c = {1, 2, 3.5}; 345a83710eSEric Fiselier T* p = c.data(); 355a83710eSEric Fiselier assert(p[0] == 1); 365a83710eSEric Fiselier assert(p[1] == 2); 375a83710eSEric Fiselier assert(p[2] == 3.5); 385a83710eSEric Fiselier } 395a83710eSEric Fiselier { 405a83710eSEric Fiselier typedef double T; 415a83710eSEric Fiselier typedef std::array<T, 0> C; 425a83710eSEric Fiselier C c = {}; 435a83710eSEric Fiselier T* p = c.data(); 4426f01c46SLouis Dionne LIBCPP_ASSERT(p != nullptr); 4559cdf90aSEric Fiselier } 4659cdf90aSEric Fiselier { 4759cdf90aSEric Fiselier typedef double T; 4859cdf90aSEric Fiselier typedef std::array<const T, 0> C; 4959cdf90aSEric Fiselier C c = {{}}; 5059cdf90aSEric Fiselier const T* p = c.data(); 5159cdf90aSEric Fiselier static_assert((std::is_same<decltype(c.data()), const T*>::value), ""); 5226f01c46SLouis Dionne LIBCPP_ASSERT(p != nullptr); 5359cdf90aSEric Fiselier } 5459cdf90aSEric Fiselier { 5559cdf90aSEric Fiselier typedef std::max_align_t T; 5659cdf90aSEric Fiselier typedef std::array<T, 0> C; 5759cdf90aSEric Fiselier const C c = {}; 5859cdf90aSEric Fiselier const T* p = c.data(); 5926f01c46SLouis Dionne LIBCPP_ASSERT(p != nullptr); 6059cdf90aSEric Fiselier std::uintptr_t pint = reinterpret_cast<std::uintptr_t>(p); 6159cdf90aSEric Fiselier assert(pint % TEST_ALIGNOF(std::max_align_t) == 0); 6259cdf90aSEric Fiselier } 6359cdf90aSEric Fiselier { 6459cdf90aSEric Fiselier typedef NoDefault T; 6559cdf90aSEric Fiselier typedef std::array<T, 0> C; 6659cdf90aSEric Fiselier C c = {}; 6759cdf90aSEric Fiselier T* p = c.data(); 6826f01c46SLouis Dionne LIBCPP_ASSERT(p != nullptr); 695a83710eSEric Fiselier } 70*2df59c50SJF Bastien 71*2df59c50SJF Bastien return 0; 725a83710eSEric Fiselier } 73