Title
Breaking change in `std::span` new `initializer_list` constructor
Status
resolved
Section
[span.cons]
Submitter
Michael Schellenberger Costa

Created on 2026-02-10.00:00:00 last changed yesterday

Messages

Date: 2026-03-31.00:00:00

[ 2026-03-31 P4144R1 was approved in Croydon. Status changed: New → Resolved. ]

Date: 2026-03-26.11:42:23

[ Croydon 2026-03-26; will be resolved by p4144r0. ]

Date: 2026-02-15.00:00:00

[ 2026-02-27; Reflector poll. ]

Set priority to 1 after reflector poll.

Votes being split between LEWG/P1 and considering this new information from deployment experience, and NAD as the breakage in the paper was already covered in [diff.cpp23.containers]. It was pointed out, that in contrast to the silent change of meaning already discussed with paper, this snippet becomes ill-formed.

Date: 2026-02-10.00:00:00

NVIDIA C++ standard library libcu++ received a bug report against our `span` implementation.

However, looking into this a bit it seems that this is a source-breaking change from the new C++26 `initializer_list` constructor of `span` in conjunction with a bad conversion sequence.

The code in question is:

#include <span>

int main() {
  bool data[4] = {true, false, true, false};
  bool* ptr = data;
  size_t size = 4;

  ::std::span<const bool> bad_span{ptr, size};

  return 0;
}

The issue is that the compiler tries a conversion sequence from `bool*` to `bool` and `size_t` to `bool`.

We probably should disallow conversions to `bool` by that constructor.

History
Date User Action Args
2026-03-31 16:42:22adminsetmessages: + msg16225
2026-03-31 16:42:22adminsetstatus: lewg -> resolved
2026-03-26 11:42:23adminsetmessages: + msg16094
2026-02-27 16:05:19adminsetmessages: + msg15977
2026-02-27 16:05:19adminsetstatus: new -> lewg
2026-02-10 00:00:00admincreate