From: Patrick Palka Date: Tue, 15 Jul 2025 19:17:23 +0000 (-0400) Subject: libstdc++: Add missing initializers for __maybe_present_t members [PR119962] X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0828600f586e75a2056a4fc7eb0a340c363d6c66;p=thirdparty%2Fgcc.git libstdc++: Add missing initializers for __maybe_present_t members [PR119962] Data members of type __maybe_present_t where the conditionally present type might be an aggregate or fundamental type need to be explicitly value-initialized (rather than implicitly default-initialized), so that default-initialization of the containing class always results in an completely initialized object. PR libstdc++/119962 libstdc++-v3/ChangeLog: * include/std/ranges (join_view::_Iterator::_M_outer): Initialize. (lazy_split_view::_OuterIter::_M_current): Initialize. (join_with_view::_Iterator::_M_outer_it): Initialize. * testsuite/std/ranges/adaptors/join.cc (test15): New test. * testsuite/std/ranges/adaptors/join_with/1.cc (test05): New test. * testsuite/std/ranges/adaptors/lazy_split.cc (test13): New test. Reviewed-by: Tomasz KamiƄski Reviewed-by: Jonathan Wakely --- diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 3a6710bd0ae1..efe62969d657 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -3022,7 +3022,8 @@ namespace views::__adaptor { _M_satisfy(); } [[no_unique_address]] - __detail::__maybe_present_t, _Outer_iter> _M_outer; + __detail::__maybe_present_t, _Outer_iter> _M_outer + = decltype(_M_outer)(); optional<_Inner_iter> _M_inner; _Parent* _M_parent = nullptr; @@ -3376,7 +3377,8 @@ namespace views::__adaptor [[no_unique_address]] __detail::__maybe_present_t, - iterator_t<_Base>> _M_current; + iterator_t<_Base>> _M_current + = decltype(_M_current)(); bool _M_trailing_empty = false; public: @@ -7400,7 +7402,8 @@ namespace views::__adaptor _Parent* _M_parent = nullptr; [[no_unique_address]] - __detail::__maybe_present_t, _OuterIter> _M_outer_it; + __detail::__maybe_present_t, _OuterIter> _M_outer_it + = decltype(_M_outer_it)(); variant<_PatternIter, _InnerIter> _M_inner_it; constexpr _OuterIter& diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc index 2861115c22a0..a9395b489919 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/join.cc @@ -233,6 +233,13 @@ test14() VERIFY( ranges::equal(v | views::join, (int[]){1, 2, 3}) ); } +void +test15() +{ + // PR libstdc++/119962 - __maybe_present_t misses initialization + constexpr decltype(views::join(views::single(views::single(0))).begin()) it; +} + int main() { @@ -250,4 +257,5 @@ main() test12(); test13(); test14(); + test15(); } diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/join_with/1.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/join_with/1.cc index 8ab30a5277da..4d55c9d3be78 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/join_with/1.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/join_with/1.cc @@ -94,6 +94,13 @@ test04() return true; } +void +test05() +{ + // PR libstdc++/119962 - __maybe_present_t misses initialization + constexpr decltype(views::join_with(views::single(views::single(0)), 0).begin()) it; +} + int main() { @@ -105,4 +112,5 @@ main() #else VERIFY(test04()); #endif + test05(); } diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/lazy_split.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/lazy_split.cc index 81fc60b362a8..321ae271bf2b 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/lazy_split.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/lazy_split.cc @@ -232,6 +232,13 @@ test12() return true; } +void +test13() +{ + // PR libstdc++/119962 - __maybe_present_t misses initialization + constexpr decltype(views::lazy_split(views::single(0), 0).begin()) it; +} + int main() { @@ -247,4 +254,5 @@ main() test10(); test11(); static_assert(test12()); + test13(); }