[PATCH v1] libstdc++: Rename _S-prefixed identifiers in <mdspan>.

Jonathan Wakely jwakely@redhat.com
Wed Sep 10 08:44:07 GMT 2025


On Wed, 10 Sept 2025 at 07:49, Luc Grosheintz <luc.grosheintz@gmail.com> wrote:
>
> In libstdc++ the prefix _S is used for static members only. In <mdspan>
> there's several type aliases that also used the prefix _S. They now use
> double underscore instead.

Thanks for revisiting these.

>
> libstdc++-v3/ChangeLog:
>
>         * include/std/mdspan (_ExtentsStorage::__base): New name for
>         _S_base.
>         (_ExtentsStorage::__storage_type): New name for _S_storage.
>         (extents::__storage_type): New name for _S_storage.
>         (layout_stride::mapping::__strides_type): New name for
>         _S_stries_t.
>         * testsuite/23_containers/mdspan/class_mandate_neg.cc: Update
>         test to the new error message.
>
> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
> ---
>  libstdc++-v3/include/std/mdspan               | 33 ++++++++++---------
>  .../23_containers/mdspan/class_mandate_neg.cc |  2 +-
>  2 files changed, 18 insertions(+), 17 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/mdspan b/libstdc++-v3/include/std/mdspan
> index 678b2619ebe..f0139a95b11 100644
> --- a/libstdc++-v3/include/std/mdspan
> +++ b/libstdc++-v3/include/std/mdspan
> @@ -148,14 +148,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>        class _ExtentsStorage : public _StaticExtents<_Extents>
>        {
>        private:
> -       using _S_base = _StaticExtents<_Extents>;
> +       using __base = _StaticExtents<_Extents>;

Looking through the other headers, we usually use _Base for this case,
and for other typedefs that are private to the class (and its
friends).

Yes, that's inconsistent with __type that we use in some internal type
traits, but in those cases __type is public and we intend it to be
used from outside the class, by code using it. e.g. constant_wrapper
uses _CwFixedValue::__type.

>        public:
> -       using _S_base::_S_rank;
> -       using _S_base::_S_rank_dynamic;
> -       using _S_base::_S_dynamic_index;
> -       using _S_base::_S_dynamic_index_inv;
> -       using _S_base::_S_static_extent;
> +       using __base::_S_rank;
> +       using __base::_S_rank_dynamic;
> +       using __base::_S_dynamic_index;
> +       using __base::_S_dynamic_index_inv;
> +       using __base::_S_static_extent;
>
>         static constexpr bool
>         _S_is_dynamic(size_t __r) noexcept
> @@ -242,8 +242,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>         }
>
>        private:
> -       using _S_storage = __array_traits<_IndexType, _S_rank_dynamic>::_Type;
> -       [[no_unique_address]] _S_storage _M_dyn_exts{};
> +       using __storage_type = __array_traits<_IndexType,
> +                                             _S_rank_dynamic>::_Type;

Since this is private, I think I'd have gone for _Storage here, but
__storage_type is OK.

> +       [[no_unique_address]] __storage_type _M_dyn_exts{};
>        };
>
>      template<typename _OIndexType, typename _SIndexType>
> @@ -259,7 +260,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      template<typename _Extents>
>        constexpr const array<size_t, _Extents::rank()>&
>        __static_extents() noexcept
> -      { return _Extents::_S_storage::_S_static_extents(); }
> +      { return _Extents::__storage_type::_S_static_extents(); }
>
>      // Pre-compute: \prod_{i = 0}^r _Extents[i], for r = 0,..., n (exclusive)
>      template<array _Extents>
> @@ -314,10 +315,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>        using rank_type = size_t;
>
>        static constexpr rank_type
> -      rank() noexcept { return _S_storage::_S_rank; }
> +      rank() noexcept { return __storage_type::_S_rank; }
>
>        static constexpr rank_type
> -      rank_dynamic() noexcept { return _S_storage::_S_rank_dynamic; }
> +      rank_dynamic() noexcept { return __storage_type::_S_rank_dynamic; }
>
>        static constexpr size_t
>        static_extent(rank_type __r) noexcept
> @@ -326,7 +327,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>         if constexpr (rank() == 0)
>           __builtin_trap();
>         else
> -         return _S_storage::_S_static_extent(__r);
> +         return __storage_type::_S_static_extent(__r);
>        }
>
>        constexpr index_type
> @@ -423,9 +424,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>        friend span<const index_type>
>        __mdspan::__dynamic_extents<extents>(const extents&, size_t, size_t);
>
> -      using _S_storage = __mdspan::_ExtentsStorage<
> +      using __storage_type = __mdspan::_ExtentsStorage<
>         _IndexType, array<size_t, sizeof...(_Extents)>{_Extents...}>;
> -      [[no_unique_address]] _S_storage _M_exts;
> +      [[no_unique_address]] __storage_type _M_exts;
>
>        template<typename _OIndexType, size_t... _OExtents>
>         friend class extents;
> @@ -1158,10 +1159,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>         }
>
>      private:
> -      using _S_strides_t = typename __array_traits<index_type,
> +      using __strides_type = typename __array_traits<index_type,
>                                                    extents_type::rank()>::_Type;
>        [[no_unique_address]] extents_type _M_extents;
> -      [[no_unique_address]] _S_strides_t _M_strides;
> +      [[no_unique_address]] __strides_type _M_strides;
>      };
>
>    template<typename _ElementType>
> diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/class_mandate_neg.cc b/libstdc++-v3/testsuite/23_containers/mdspan/class_mandate_neg.cc
> index de19b6d85c9..787e6d801ce 100644
> --- a/libstdc++-v3/testsuite/23_containers/mdspan/class_mandate_neg.cc
> +++ b/libstdc++-v3/testsuite/23_containers/mdspan/class_mandate_neg.cc
> @@ -35,7 +35,7 @@ test_element_type_mismatch()
>  static_assert(test_element_type_mismatch());
>
>  // { dg-prune-output "Extents must be a specialization of std::extents" }
> -// { dg-prune-output "no type named '_S_storage'" }
> +// { dg-prune-output "no type named '__storage_type'" }
>  // { dg-prune-output "non-constant condition" }
>  // { dg-prune-output "static assertion failed" }
>  // { dg-prune-output "__glibcxx_assert" }
> --
> 2.50.1
>



More information about the Libstdc++ mailing list