]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Do not use list-initialization in std::span members [PR120997]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 8 Jul 2025 13:56:39 +0000 (14:56 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 9 Jul 2025 16:56:21 +0000 (17:56 +0100)
commita72d0e1a8bf0770ddf1d8d0ebe589f92a4fab4ef
tree58c163c83f314a887552cf558f17069e862a992a
parent82dd19890b6139c4bac2385068a68613920ae1a2
libstdc++: Do not use list-initialization in std::span members [PR120997]

As the bug report shows, for span<const bool> the return statements of
the form `return {data(), count};` will use the new C++26 constructor,
span(initializer_list<element_type>).

Although the conversions from data() to bool and count to bool are
narrowing and should be ill-formed, in system headers the narrowing
diagnostics are suppressed. In any case, even if the compiler diagnosed
them as ill-formed, we still don't want the initializer_list constructor
to be used. We want to use the span(element_type*, size_t) constructor
instead.

Replace the braced-init-list uses with S(data(), count) where S is the
correct return type. We need to make similar changes in the C++26
working draft, which will be taken care of via an LWG issue.

libstdc++-v3/ChangeLog:

PR libstdc++/120997
* include/std/span (span::first, span::last, span::subspan): Do
not use braced-init-list for return statements.
* testsuite/23_containers/span/120997.cc: New test.
libstdc++-v3/include/std/span
libstdc++-v3/testsuite/23_containers/span/120997.cc [new file with mode: 0644]