[libcxx-commits] [libcxx] b0c769a - [libc++][mdspan] Fix extents CTAD (#68737)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Oct 12 12:09:41 PDT 2023


Author: Christian Trott
Date: 2023-10-12T13:09:36-06:00
New Revision: b0c769a80b5f019f189f67d20e6b24971b435970

URL: https://github.com/llvm/llvm-project/commit/b0c769a80b5f019f189f67d20e6b24971b435970
DIFF: https://github.com/llvm/llvm-project/commit/b0c769a80b5f019f189f67d20e6b24971b435970.diff

LOG: [libc++][mdspan] Fix extents CTAD (#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

Added: 
    

Modified: 
    libcxx/include/__mdspan/extents.h
    libcxx/test/std/containers/views/mdspan/extents/ctad.pass.cpp

Removed: 
    


################################################################################
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..3fc7c707f036ab2 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,13 @@
 #include "../ConvertibleToIntegral.h"
 #include "test_macros.h"
 
+struct NoDefaultCtorIndex {
+  size_t value;
+  constexpr NoDefaultCtorIndex() = delete;
+  constexpr NoDefaultCtorIndex(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 +42,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(NoDefaultCtorIndex{1}, NoDefaultCtorIndex{2}), std::extents<std::size_t, D, D>(1, 2));
   return true;
 }
 


        


More information about the libcxx-commits mailing list