From e7663434eef96c72b6093b565d802f5a718f4797 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 25 Jan 2025 19:18:22 +0200 Subject: [PATCH] Add array_init_test_cx.cpp --- test/Jamfile.v2 | 4 ++ test/array_init_test_cx.cpp | 74 +++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 test/array_init_test_cx.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 19f857e..551e8e7 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -49,4 +49,8 @@ run array_get_test.cpp ; # +compile array_init_test_cx.cpp ; + +# + run quick.cpp ; diff --git a/test/array_init_test_cx.cpp b/test/array_init_test_cx.cpp new file mode 100644 index 0000000..1df53f5 --- /dev/null +++ b/test/array_init_test_cx.cpp @@ -0,0 +1,74 @@ +// Copyright 2025 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include + +#if defined(BOOST_NO_CXX11_CONSTEXPR) + +BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX11_CONSTEXPR is defined") + +#else + +#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) + +template void test1() +{ + constexpr boost::array a = {{}}; + + STATIC_ASSERT( a[0] == 0 ); +} + +template void test2() +{ + constexpr boost::array a = {}; + + STATIC_ASSERT( a[0] == 0 ); + STATIC_ASSERT( a[1] == 0 ); +} + +template void test3() +{ + constexpr boost::array a = {{ 1, 2, 3 }}; + + STATIC_ASSERT( a[0] == 1 ); + STATIC_ASSERT( a[1] == 2 ); + STATIC_ASSERT( a[2] == 3 ); +} + +template void test4() +{ + constexpr boost::array a = { 1, 2, 3, 4 }; + + STATIC_ASSERT( a[0] == 1 ); + STATIC_ASSERT( a[1] == 2 ); + STATIC_ASSERT( a[2] == 3 ); + STATIC_ASSERT( a[3] == 4 ); +} + +template void test5() +{ + // constexpr boost::array a = {{}}; +} + +template void test6() +{ + constexpr boost::array a = {}; + (void)a; +} + +int main() +{ + test1(); + test2(); + test3(); + test4(); + test5(); + test6(); +} + +#endif