[libcxx-commits] [libcxx] [libc++][mdspan] Fix extents CTAD (PR #68737)
Christian Trott via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Oct 10 12:15:41 PDT 2023
https://github.com/crtrott created https://github.com/llvm/llvm-project/pull/68737
extents CTAD was requiring default constructibility of the extent arguments due to the way we implemented a pack expansion. This requirement is not in the standard.
Reported in issue #68671 https://github.com/llvm/llvm-project/issues/68671 by @hewillk.
Fixes #68671
>From eda9969260ad8b47afcbd026ef554769b52eea69 Mon Sep 17 00:00:00 2001
From: Christian Trott <crtrott at sandia.gov>
Date: Tue, 10 Oct 2023 13:08:33 -0600
Subject: [PATCH] [libc++][mdspan] Fix extents CTAD
extents CTAD was requiring default constructibility of the extent arguments
due to the way we implemented a pack expansion. This requirement is not in
the standard.
Reported in issue #68671 https://github.com/llvm/llvm-project/issues/68671
by @hewillk.
Fixes #68671
---
libcxx/include/__mdspan/extents.h | 2 +-
.../test/std/containers/views/mdspan/extents/ctad.pass.cpp | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/libcxx/include/__mdspan/extents.h b/libcxx/include/__mdspan/extents.h
index a510220d4096a2f..f6bcd940ee6077d 100644
--- a/libcxx/include/__mdspan/extents.h
+++ b/libcxx/include/__mdspan/extents.h
@@ -456,7 +456,7 @@ using dextents = typename __mdspan_detail::__make_dextents<_IndexType, _Rank>::t
// Deduction guide for extents
template <class... _IndexTypes>
-extents(_IndexTypes...) -> extents<size_t, size_t((_IndexTypes(), dynamic_extent))...>;
+extents(_IndexTypes...) -> extents<size_t, size_t(((void)sizeof(_IndexTypes), dynamic_extent))...>;
namespace __mdspan_detail {
diff --git a/libcxx/test/std/containers/views/mdspan/extents/ctad.pass.cpp b/libcxx/test/std/containers/views/mdspan/extents/ctad.pass.cpp
index 2a3da30bb936600..fed16b3fc91b459 100644
--- a/libcxx/test/std/containers/views/mdspan/extents/ctad.pass.cpp
+++ b/libcxx/test/std/containers/views/mdspan/extents/ctad.pass.cpp
@@ -21,6 +21,12 @@
#include "../ConvertibleToIntegral.h"
#include "test_macros.h"
+struct S {
+ size_t value;
+ constexpr S(size_t val):value(val) {};
+ constexpr operator size_t() const noexcept { return value; }
+};
+
template <class E, class Expected>
constexpr void test(E e, Expected expected) {
ASSERT_SAME_TYPE(E, Expected);
@@ -35,6 +41,7 @@ constexpr bool test() {
test(std::extents(1, 2u), std::extents<std::size_t, D, D>(1, 2u));
test(std::extents(1, 2u, 3, 4, 5, 6, 7, 8, 9),
std::extents<std::size_t, D, D, D, D, D, D, D, D, D>(1, 2u, 3, 4, 5, 6, 7, 8, 9));
+ test(std::extents(S{1}, S{2}), std::extents<std::size_t, D, D>(1, 2u));
return true;
}
More information about the libcxx-commits
mailing list