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 27*98f77828SJoerg Sonnenberger #if TEST_STD_VER < 11 28*98f77828SJoerg Sonnenberger struct natural_alignment { 29*98f77828SJoerg Sonnenberger long t1; 30*98f77828SJoerg Sonnenberger long long t2; 31*98f77828SJoerg Sonnenberger double t3; 32*98f77828SJoerg Sonnenberger long double t4; 33*98f77828SJoerg Sonnenberger }; 34*98f77828SJoerg Sonnenberger #endif 35db49965aSMarshall Clow 362df59c50SJF Bastien int main(int, char**) 375a83710eSEric Fiselier { 385a83710eSEric Fiselier { 395a83710eSEric Fiselier typedef double T; 405a83710eSEric Fiselier typedef std::array<T, 3> C; 415a83710eSEric Fiselier C c = {1, 2, 3.5}; 425a83710eSEric Fiselier T* p = c.data(); 435a83710eSEric Fiselier assert(p[0] == 1); 445a83710eSEric Fiselier assert(p[1] == 2); 455a83710eSEric Fiselier assert(p[2] == 3.5); 465a83710eSEric Fiselier } 475a83710eSEric Fiselier { 485a83710eSEric Fiselier typedef double T; 495a83710eSEric Fiselier typedef std::array<T, 0> C; 505a83710eSEric Fiselier C c = {}; 515a83710eSEric Fiselier T* p = c.data(); 5226f01c46SLouis Dionne LIBCPP_ASSERT(p != nullptr); 5359cdf90aSEric Fiselier } 5459cdf90aSEric Fiselier { 5559cdf90aSEric Fiselier typedef double T; 5659cdf90aSEric Fiselier typedef std::array<const T, 0> C; 5759cdf90aSEric Fiselier C c = {{}}; 5859cdf90aSEric Fiselier const T* p = c.data(); 5959cdf90aSEric Fiselier static_assert((std::is_same<decltype(c.data()), const T*>::value), ""); 6026f01c46SLouis Dionne LIBCPP_ASSERT(p != nullptr); 6159cdf90aSEric Fiselier } 6259cdf90aSEric Fiselier { 63*98f77828SJoerg Sonnenberger #if TEST_STD_VER < 11 64*98f77828SJoerg Sonnenberger typedef natural_alignment T; 65*98f77828SJoerg Sonnenberger #else 6659cdf90aSEric Fiselier typedef std::max_align_t T; 67*98f77828SJoerg Sonnenberger #endif 6859cdf90aSEric Fiselier typedef std::array<T, 0> C; 6959cdf90aSEric Fiselier const C c = {}; 7059cdf90aSEric Fiselier const T* p = c.data(); 7126f01c46SLouis Dionne LIBCPP_ASSERT(p != nullptr); 7259cdf90aSEric Fiselier std::uintptr_t pint = reinterpret_cast<std::uintptr_t>(p); 73*98f77828SJoerg Sonnenberger assert(pint % TEST_ALIGNOF(T) == 0); 7459cdf90aSEric Fiselier } 7559cdf90aSEric Fiselier { 7659cdf90aSEric Fiselier typedef NoDefault T; 7759cdf90aSEric Fiselier typedef std::array<T, 0> C; 7859cdf90aSEric Fiselier C c = {}; 7959cdf90aSEric Fiselier T* p = c.data(); 8026f01c46SLouis Dionne LIBCPP_ASSERT(p != nullptr); 815a83710eSEric Fiselier } 822df59c50SJF Bastien 832df59c50SJF Bastien return 0; 845a83710eSEric Fiselier } 85