Skip to content

Commit 4563d39

Browse files
committed
New issue from Jonathan: bitset(const CharT*) constructor needs to be constrained
1 parent 7537bca commit 4563d39

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

xml/issue4294.xml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4294" status="New">
5+
<title>`bitset(const CharT*)` constructor needs to be constrained</title>
6+
<section><sref ref="[bitset.cons]"/></section>
7+
<submitter>Jonathan Wakely</submitter>
8+
<date>12 Jul 2025</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<p>
13+
This code might be ill-formed, with an error outside the immediate context
14+
that users cannot prevent:
15+
<blockquote><pre><code>
16+
#include &lt;bitset&gt;
17+
struct NonTrivial { ~NonTrivial() { } };
18+
static_assert( ! std::is_constructible_v&lt;std::bitset&lt;1&gt;, NonTrivial*&gt; );
19+
</code></pre></blockquote>
20+
</p>
21+
<p>
22+
The problem is that the `bitset(const CharT*)` constructor tries to instantiate
23+
<code>basic_string_view&lt;NonTrivial&gt;</code> to find its `size_type`,
24+
and that instantiation might ill-formed (e.g. if `std::basic_string_view` or
25+
`std::char_traits` has a static assert enforcing the requirement for their
26+
character type to be sufficiently char-like (<sref ref="[strings.general]"/>).
27+
</p>
28+
</discussion>
29+
30+
<resolution>
31+
<p>
32+
This wording is relative to <paper num="N5008"/>.
33+
</p>
34+
35+
<ol>
36+
37+
<li><p>Modify <sref ref="[bitset.cons]"/> as indicated:</p>
38+
39+
<blockquote>
40+
<pre><code>
41+
template&lt;class charT&gt;
42+
constexpr explicit bitset(
43+
const charT* str,
44+
typename basic_string_view&lt;charT&gt;::size_type n = basic_string_view&lt;charT&gt;::npos,
45+
charT zero = charT(’0’),
46+
charT one = charT(’1’));
47+
</code></pre>
48+
<blockquote>
49+
<p>
50+
<ins>-?- <i>Constraints</i>:
51+
<code>is_trivially_default_constructible_v&lt;charT&gt;</code> is `true`.
52+
</ins>
53+
</p>
54+
<p>-8- <i>Effects</i>: As if by:
55+
<blockquote>
56+
<pre><code>bitset(n == basic_string_view&lt;charT&gt;::npos
57+
? basic_string_view&lt;charT&gt;(str)
58+
: basic_string_view&lt;charT&gt;(str, n),
59+
0, n, zero, one)
60+
</code></pre>
61+
</blockquote>
62+
</p>
63+
</blockquote>
64+
</blockquote>
65+
</li>
66+
</ol>
67+
68+
69+
</resolution>
70+
71+
</issue>

0 commit comments

Comments
 (0)