[libcxx-commits] [libcxx] [libc++][mdspan][NFC] Remove redundant syntax and keywords (PR #175024)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jan 9 04:03:03 PST 2026


================
@@ -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&)
----------------
frederick-vs-ja wrote:

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:
```C++
#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](https://godbolt.org/z/1T1Kjfdxd)). 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.

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


More information about the libcxx-commits mailing list