[libcxx-commits] [libcxx] [libc++][mdspan] Fix extents CTAD (PR #68737)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Oct 10 12:17:28 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Christian Trott (crtrott)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/68737.diff
2 Files Affected:
- (modified) libcxx/include/__mdspan/extents.h (+1-1)
- (modified) libcxx/test/std/containers/views/mdspan/extents/ctad.pass.cpp (+7)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/68737
More information about the libcxx-commits
mailing list