[PATCH v5 1/7] libstdc++: Silence warning in mdspan.
Luc Grosheintz
luc.grosheintz@gmail.com
Mon Dec 8 20:23:40 GMT 2025
Splitting the tests for submdspan triggered a compiler warning. This
commit changes the implementation of __dynamic_extents. In particular,
how the span is created. Functionally, the two are equivalent.
libstdc++-v3/ChangeLog:
* include/std/mdspan (_ExtentsStorage::_M_dynamic_extents):
Create span from pointer + size, not begin and end iterators.
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
---
Without this change after splitting the test, the instantiation for
certain layouts, i.e. padded with PaddingSize 8 (both left and right),
compiles with a warning.
libstdc++-v3/include/mdspan:276: warning: '<unknown>' may be used uninitialized [-Wmaybe-uninitialized]
The changes in this commit silence the warning. Debugging the issue is
made very difficult by the following:
1. The error messages doesn't list which instantiation causes the
warning. It simply states: "In header included from this other header,
the might be an uninitialized value.
2. Using bisection to narrow down what causes the warning to appear
leads to: neither half.
3. Without the addition flags, the tests compile, run and pass.
4. Neither `-fsanitize=address` nor `-fsanitize=undefined` find
anything.
5. The most likely reason would be that we're doing pointer arithmetic
with null pointers; but I can't see it. I've looked several times and
__dynamic_extents isn't called when all extents are static and the
warning messages suggests that the dynamic rank is 3.
Here's the full output:
In file included from libstdc++-v3/testsuite/23_containers/mdspan/submdspan/selections/testcases.h:1,
from libstdc++-v3/testsuite/23_containers/mdspan/submdspan/selections/left_padded_8.cc:2:
In member function 'constexpr std::span<const _IndexType> std::__mdspan::_ExtentsStorage<_IndexType, _Extents>::_M_dynamic_extents(std::size_t, std::size_t) const requires _Extents.size() > 0 [with _IndexType = long unsigned int; array<...auto...> _Extents = std::array<long unsigned int, 3>{std::__array_traits<long unsigned int, 3>::_Type{18446744073709551615, 18446744073709551615, 18446744073709551615}}]',
inlined from 'constexpr std::span<const typename _Extents::index_type> std::__mdspan::__dynamic_extents(const _Extents&, std::size_t, std::size_t) [with _Extents = std::extents<long unsigned int, 18446744073709551615, 18446744073709551615, 18446744073709551615>]' at libstdc++-v3/include/mdspan:344,
inlined from 'constexpr bool std::__mdspan::__is_representable_extents(const _Extents&) [with _Extents = std::extents<long unsigned int, 18446744073709551615, 18446744073709551615, 18446744073709551615>]' at libstdc++-v3/include/mdspan:774,
inlined from 'constexpr std::__mdspan::_PaddedStorage<_PaddingValue, _Extents, _LayoutTraits>::_PaddedStorage(const _Extents&) [with long unsigned int _PaddingValue = 8; _Extents = std::extents<long unsigned int, 18446744073709551615, 18446744073709551615, 18446744073709551615>; _LayoutTraits = std::__mdspan::_LeftPaddedLayoutTraits<3>]' at libstdc++-v3/include/mdspan:2271:
libstdc++-v3/include/mdspan:276: warning: '<unknown>' may be used uninitialized [-Wmaybe-uninitialized]
In file included from libstdc++-v3/include/mdspan:36:
libstdc++-v3/include/span: In constructor 'constexpr std::__mdspan::_PaddedStorage<_PaddingValue, _Extents, _LayoutTraits>::_PaddedStorage(const _Extents&) [with long unsigned int _PaddingValue = 8; _Extents = std::extents<long unsigned int, 18446744073709551615, 18446744073709551615, 18446744073709551615>; _LayoutTraits = std::__mdspan::_LeftPaddedLayoutTraits<3>]':
libstdc++-v3/include/span:194: note: by argument 3 of type 'const long unsigned int*' to 'constexpr std::span<_Type, _Extent>::span(_It, _End) [with _It = const long unsigned int*; _End = const long unsigned int*; _Type = const long unsigned int; long unsigned int _Extent = 18446744073709551615]' declared here
libstdc++-v3/include/std/mdspan | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libstdc++-v3/include/std/mdspan b/libstdc++-v3/include/std/mdspan
index 03cc4f02a1c..cef658da470 100644
--- a/libstdc++-v3/include/std/mdspan
+++ b/libstdc++-v3/include/std/mdspan
@@ -271,7 +271,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
requires (_Extents.size() > 0)
{
return {_M_dyn_exts + _S_dynamic_index(__begin),
- _M_dyn_exts + _S_dynamic_index(__end)};
+ _S_dynamic_index(__end) - _S_dynamic_index(__begin)};
}
private:
--
2.52.0
More information about the Libstdc++
mailing list