Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++][mdspan] Fix extents CTAD #68737

Merged
merged 1 commit into from
Oct 12, 2023
Merged

Conversation

crtrott
Copy link
Contributor

@crtrott crtrott commented Oct 10, 2023

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 #68671 by @hewillk.

Fixes #68671

@crtrott crtrott requested a review from a team as a code owner October 10, 2023 19:15
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Oct 10, 2023
@crtrott crtrott requested a review from ldionne October 10, 2023 19:16
@llvmbot
Copy link
Member

llvmbot commented Oct 10, 2023

@llvm/pr-subscribers-libcxx

Author: Christian Trott (crtrott)

Changes

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 #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 --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;
 }
 

@github-actions
Copy link

github-actions bot commented Oct 10, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

@crtrott crtrott force-pushed the fix-extents-ctad-68671 branch from eda9969 to 845d280 Compare October 10, 2023 19:24
@crtrott
Copy link
Contributor Author

crtrott commented Oct 10, 2023

Ah I see clang-format is now also checked for tests. Good to know.

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically LGTM but I have a nit suggestion. Thanks for fixing!

@crtrott crtrott force-pushed the fix-extents-ctad-68671 branch from 845d280 to b8f2ab6 Compare October 10, 2023 20:48
Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Please squash and merge once CI is green.

@crtrott
Copy link
Contributor Author

crtrott commented Oct 11, 2023

How do we retest? Looks like it failed in generated output due to some string file formatting issue which likely was caused elsewhere?

@crtrott
Copy link
Contributor Author

crtrott commented Oct 11, 2023

Retest this please.

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 llvm#68671 llvm#68671
by @hewillk.

Fixes llvm#68671
@crtrott crtrott force-pushed the fix-extents-ctad-68671 branch from b8f2ab6 to 134d609 Compare October 12, 2023 15:25
@crtrott
Copy link
Contributor Author

crtrott commented Oct 12, 2023

I just rebased on main again, which retriggered the build

@crtrott crtrott merged commit b0c769a into llvm:main Oct 12, 2023
@crtrott crtrott deleted the fix-extents-ctad-68671 branch October 12, 2023 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

<mdspan>: std::extents's CTAD unconditionally constrains argument types to be default-constructible
4 participants