|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4293" status="New"> |
| 5 | +<title>span::subspan/first/last chooses wrong constructor when T is const-qualified bool</title> |
| 6 | +<section><sref ref="[span.sub]"/></section> |
| 7 | +<submitter>Yuhan Liu</submitter> |
| 8 | +<date>11 Jul 2025</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +In section <sref ref="[span.sub]"/>, paragraphs p12, p14, and p16 erroneously |
| 14 | +use the initializer list constructor for span instead of the intended |
| 15 | +iterator/count constructor. |
| 16 | +</p> |
| 17 | +<p> |
| 18 | +Specifically, in these paragraphs, the standard states: |
| 19 | +<blockquote> |
| 20 | +<i>Effects</i>: Equivalent to: `return {data(), count};` |
| 21 | +</blockquote> |
| 22 | +or some variant of `return {pointer, size}`. As reported in |
| 23 | +<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120997">GCC bug 120997</a> |
| 24 | +this results in a span that points to invalid stack memory. |
| 25 | +This can be reproduced on GCC 15.1 for subspan, first, and last: |
| 26 | +<a href="https://godbolt.org/z/r9nrdWscq">https://godbolt.org/z/r9nrdWscq</a>. |
| 27 | +</p> |
| 28 | +<p> |
| 29 | +A proposed fix (thanks to Jonathan Wakely) could look like this following: |
| 30 | +<blockquote> |
| 31 | +`return span<element_type>(data(), count);` |
| 32 | +</blockquote> |
| 33 | +for the affected paragraphs, |
| 34 | +which would explicitly specify the constructor used. |
| 35 | +</p> |
| 36 | +</discussion> |
| 37 | + |
| 38 | +<resolution> |
| 39 | +<p> |
| 40 | +</p> |
| 41 | +</resolution> |
| 42 | + |
| 43 | +</issue> |
0 commit comments