]> 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>
Fri, 11 Jul 2025 08:38:06 +0000 (09:38 +0100)
commitab3781665da064985d66de0c895cc43588179cb6
tree5bf5dd219b2541ee7a6e75eaeb3040b5051de89c
parent2de64a64b41989682dcdc621fd72fe107fec8b95
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.

(cherry picked from commit a72d0e1a8bf0770ddf1d8d0ebe589f92a4fab4ef)
libstdc++-v3/include/std/span
libstdc++-v3/testsuite/23_containers/span/120997.cc [new file with mode: 0644]