Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[libc++][mdspan][NFC] Remove redundant else and trailing semicolons#175024

Merged
frederick-vs-ja merged 1 commit intollvm:mainfrom
eiytoq:nfc-mdspan
Jan 10, 2026
Merged

[libc++][mdspan][NFC] Remove redundant else and trailing semicolons#175024
frederick-vs-ja merged 1 commit intollvm:mainfrom
eiytoq:nfc-mdspan

Conversation

@eiytoq
Copy link
Copy Markdown
Contributor

@eiytoq eiytoq commented Jan 8, 2026

No description provided.

@eiytoq eiytoq requested a review from a team as a code owner January 8, 2026 16:58
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 8, 2026

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 8, 2026
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Jan 8, 2026

@llvm/pr-subscribers-libcxx

Author: eiytoq (eiytoq)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/175024.diff

2 Files Affected:

  • (modified) libcxx/include/__mdspan/layout_stride.h (+4-5)
  • (modified) libcxx/include/__mdspan/mdspan.h (+13-14)
diff --git a/libcxx/include/__mdspan/layout_stride.h b/libcxx/include/__mdspan/layout_stride.h
index 9d77d71bc3598..eb22475756fde 100644
--- a/libcxx/include/__mdspan/layout_stride.h
+++ b/libcxx/include/__mdspan/layout_stride.h
@@ -272,11 +272,10 @@ class layout_stride::mapping {
       return [&]<size_t... _Pos>(index_sequence<_Pos...>) {
         if ((__extents_.extent(_Pos) * ... * 1) == 0)
           return static_cast<index_type>(0);
-        else
-          return static_cast<index_type>(
-              static_cast<index_type>(1) +
-              (((__extents_.extent(_Pos) - static_cast<index_type>(1)) * __strides_[_Pos]) + ... +
-               static_cast<index_type>(0)));
+
+        return static_cast<index_type>(
+            static_cast<index_type>(1) + (((__extents_.extent(_Pos) - static_cast<index_type>(1)) * __strides_[_Pos]) +
+                                          ... + static_cast<index_type>(0)));
       }(make_index_sequence<__rank_>());
     }
   }
diff --git a/libcxx/include/__mdspan/mdspan.h b/libcxx/include/__mdspan/mdspan.h
index 9d3d35cd558a1..8467f923d64b1 100644
--- a/libcxx/include/__mdspan/mdspan.h
+++ b/libcxx/include/__mdspan/mdspan.h
@@ -96,9 +96,8 @@ class mdspan {
   }
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr index_type extent(rank_type __r) const noexcept {
     return __map_.extents().extent(__r);
-  };
+  }
 
-public:
   //--------------------------------------------------------------------------------
   // [mdspan.mdspan.cons], mdspan constructors, assignment, and destructor
 
@@ -242,26 +241,26 @@ class mdspan {
 
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const extents_type& extents() const noexcept {
     return __map_.extents();
-  };
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const data_handle_type& data_handle() const noexcept { return __ptr_; };
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const mapping_type& mapping() const noexcept { return __map_; };
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const accessor_type& accessor() const noexcept { return __acc_; };
+  }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const data_handle_type& data_handle() const noexcept { return __ptr_; }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const mapping_type& mapping() const noexcept { return __map_; }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const accessor_type& accessor() const noexcept { return __acc_; }
 
   // per LWG-4021 "mdspan::is_always_meow() should be noexcept"
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr bool is_always_unique() noexcept {
     return mapping_type::is_always_unique();
-  };
+  }
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr bool is_always_exhaustive() noexcept {
     return mapping_type::is_always_exhaustive();
-  };
+  }
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr bool is_always_strided() noexcept {
     return mapping_type::is_always_strided();
-  };
+  }
 
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool is_unique() const { return __map_.is_unique(); };
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool is_exhaustive() const { return __map_.is_exhaustive(); };
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool is_strided() const { return __map_.is_strided(); };
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr index_type stride(rank_type __r) const { return __map_.stride(__r); };
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool is_unique() const { return __map_.is_unique(); }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool is_exhaustive() const { return __map_.is_exhaustive(); }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool is_strided() const { return __map_.is_strided(); }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr index_type stride(rank_type __r) const { return __map_.stride(__r); }
 
 private:
   _LIBCPP_NO_UNIQUE_ADDRESS data_handle_type __ptr_{};
@@ -310,7 +309,7 @@ mdspan(_ElementType*, const _MappingType&)
     -> mdspan<_ElementType, typename _MappingType::extents_type, typename _MappingType::layout_type>;
 
 template <class _MappingType, class _AccessorType>
-mdspan(const typename _AccessorType::data_handle_type, const _MappingType&, const _AccessorType&)
+mdspan(typename _AccessorType::data_handle_type, const _MappingType&, const _AccessorType&)
     -> mdspan<typename _AccessorType::element_type,
               typename _MappingType::extents_type,
               typename _MappingType::layout_type,

@eiytoq eiytoq changed the title [libcxx][mdspan][NFC] Remove redundant syntax and keywords [libc][mdspan][NFC] Remove redundant syntax and keywords Jan 8, 2026
@eiytoq eiytoq changed the title [libc][mdspan][NFC] Remove redundant syntax and keywords [libc++][mdspan][NFC] Remove redundant syntax and keywords Jan 8, 2026
Copy link
Copy Markdown
Contributor

@H-G-Hristov H-G-Hristov left a comment

Choose a reason for hiding this comment

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

These changes look reasonable to me with one exception bellow

Comment thread libcxx/include/__mdspan/mdspan.h Outdated
Comment thread libcxx/include/__mdspan/mdspan.h Outdated
@@ -310,7 +309,7 @@ mdspan(_ElementType*, const _MappingType&)
-> mdspan<_ElementType, typename _MappingType::extents_type, typename _MappingType::layout_type>;

template <class _MappingType, class _AccessorType>
mdspan(const typename _AccessorType::data_handle_type, const _MappingType&, const _AccessorType&)
mdspan(const typename _AccessorType::data_handle_type&, const _MappingType&, const _AccessorType&)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Change in this line looks like bugfix and is probably beyond of the scope of NFC. I think it's better to split it into another PR.

Consider this example:

#include <cstddef>
#include <mdspan>

int main() {
  int a[1]{};
  int * volatile p = a;
  (void)std::mdspan(p, std::layout_left::mapping<std::extents<std::size_t, 1>>{}, std::default_accessor<int>{});
}

Currently it compiles with libc++ (Godbolt link). But according to the standard requirement, it should be rejected, because a volatile data_handle_type lvalue can't be bound to const data_handle_type&.

I guess it's better to make this deduction guide to take data_handle_type by value, because the corresponding construction takes it by value. But this would require an LWG issue. If the potential LWG issue is accepted, the current implementation strategy will become correct and we should just remove the superfluous const here. CC @crtrott.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Submitted LWG4511 for this.

@frederick-vs-ja frederick-vs-ja changed the title [libc++][mdspan][NFC] Remove redundant syntax and keywords [libc++][mdspan][NFC] Remove redundant else and trailing semicolon Jan 10, 2026
@frederick-vs-ja frederick-vs-ja changed the title [libc++][mdspan][NFC] Remove redundant else and trailing semicolon [libc++][mdspan][NFC] Remove redundant else and trailing semicolons Jan 10, 2026
@frederick-vs-ja
Copy link
Copy Markdown
Contributor

I slightly rephrased the PR title to explicitly say "else and trailing semicolons".

@frederick-vs-ja frederick-vs-ja merged commit 91f7e7f into llvm:main Jan 10, 2026
80 checks passed
@github-actions
Copy link
Copy Markdown

@eiytoq Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@eiytoq eiytoq deleted the nfc-mdspan branch January 12, 2026 15:45
Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Jan 18, 2026
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.

4 participants