From 2323bd7452339eb57d6ac7fe494ed1ae7d11d567 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Thu, 26 Sep 2024 09:22:35 -0400 Subject: [PATCH] make sure to initialize unused metadata data in constexpr-rank arrays --- btas/array_adaptor.h | 2 ++ unittest/range_test.cc | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/btas/array_adaptor.h b/btas/array_adaptor.h index fc8bac2b..fb314e0d 100644 --- a/btas/array_adaptor.h +++ b/btas/array_adaptor.h @@ -32,6 +32,8 @@ namespace btas { static array construct(std::size_t n) { assert(n <= N); array result; + // fill elements n+1 ... N-1 with zeroes + std::fill_n(result.begin() + n, N - n, value_type{}); return result; } static array construct(std::size_t n, T value) { diff --git a/unittest/range_test.cc b/unittest/range_test.cc index b95b6619..c48f9f33 100644 --- a/unittest/range_test.cc +++ b/unittest/range_test.cc @@ -70,6 +70,10 @@ TEST_CASE("Range") typedef RangeNd> Range3d; Range3d x; CHECK(x.rank()== 3); + CHECK(x.area()== 0); + Range3d x1(std::array{},std::array{}); + CHECK(x1.rank()== 3); + CHECK(x1.area()== 0); } SECTION("Col-major std::vector-based Range") {