Skip to content

Commit 0802eb5

Browse files
committed
New issue from Matthias Kretz: "The simd::basic_mask(bool) overload needs to be more constrained "
1 parent c425f80 commit 0802eb5

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

xml/issue4382.xml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4382" status="New">
5+
<title>The <tt>simd::basic_mask(bool)</tt> overload needs to be more constrained
6+
</title>
7+
<section>
8+
<sref ref="[simd.mask.ctor]"/>
9+
</section>
10+
<submitter>Matthias Kretz</submitter>
11+
<date>24 Sep 2025</date>
12+
<priority>99</priority>
13+
14+
<discussion>
15+
<p>
16+
<sref ref="[simd.mask.ctor]"/> defines the overloads `basic_mask(bool)` and
17+
`basic_mask(unsigned_integral auto)`. This leads to the following pitfall:
18+
</p>
19+
<blockquote><pre>
20+
auto g0() {
21+
unsigned short k = 0xf;
22+
return simd::mask&lt;float, 8&gt;(k); // mov eax, 15
23+
}
24+
25+
auto g1() {
26+
unsigned short k = 0xf;
27+
return simd::mask&lt;float, 8&gt;(k >> 1); // mov eax, -1 ⚠️
28+
}
29+
30+
auto g2() {
31+
unsigned int k = 0xf;
32+
return simd::mask&lt;float, 8&gt;(k >> 1); // mov eax, 7
33+
}
34+
</pre></blockquote>
35+
<p>
36+
In `g1`, `k` is promoted to `int`, shifted and then passed to
37+
the mask constructor. Instead of failing, `int(0x7)` is
38+
converted to `bool` and the mask thus initialized to all `true`.
39+
<p/>
40+
Also consider:
41+
</p>
42+
<ol>
43+
<li><p><tt>simd::mask&lt;float&gt;(true_type());</tt></p></li>
44+
<li><p><tt>unsigned_integral&lt;bool&gt;</tt> is `true` =>
45+
<tt>same_as&lt;bool&gt; auto</tt> instead of 'bool' makes
46+
the overload set ambiguous</p></li>
47+
<li><p>`float` is convertible to `bool`, thus
48+
<tt>simd::mask&lt;float&gt;(1.f)</tt> continues to compile</p></li>
49+
</ol>
50+
</discussion>
51+
52+
<resolution>
53+
<p>
54+
This wording is relative to <paper num="N5014"/>.
55+
</p>
56+
57+
<ol>
58+
59+
<li><p>Modify <sref ref="[simd.mask.overview]"/>, <tt>class template basic_mask</tt> synopsis, as indicated:</p>
60+
61+
<blockquote>
62+
<pre>
63+
namespace std::simd {
64+
template&lt;size_t Bytes, class Abi&gt; class basic_mask {
65+
public:
66+
[&hellip;]
67+
68+
constexpr basic_mask() noexcept = default;
69+
70+
// <i><sref ref="[simd.mask.ctor]"/>, basic_mask constructors</i>
71+
constexpr explicit basic_mask(value_type) noexcept;
72+
template&lt;size_t UBytes, class UAbi&gt;
73+
constexpr explicit basic_mask(const basic_mask&lt;UBytes, UAbi&gt;&amp;) noexcept;
74+
template&lt;class G&gt;
75+
constexpr explicit basic_mask(G&amp;&amp; gen) noexcept;
76+
constexpr basic_mask(const bitset&lt;size()&gt;&amp; b) noexcept;
77+
constexpr explicit basic_mask(unsigned_integral auto val) noexcept;
78+
<ins>basic_mask(signed_integral auto) = delete;</ins>
79+
80+
[&hellip;]
81+
};
82+
}
83+
</pre>
84+
</blockquote>
85+
86+
</li>
87+
88+
</ol>
89+
</resolution>
90+
91+
</issue>

0 commit comments

Comments
 (0)