-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Description
Hey, I recently presented cplusplus/papers#2384 (https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3765r0.html) in Kona 2025 during the WG21 meeting.
The goal of the paper was to introduce a deprecation for the implicit conversion in cases like:
std::string_view str = /* ... */;
if (str.ends_with('\n' || str.ends_with('\r'))) {
// ...
}This is an extremely evil bug: it's equivalent to checking whether str ends with U+0001 START OF HEADING (assuming ASCII char). See the paper for more discussion. In the ASCII/Unicode interpretation:
falseis converted to U+0000 NULLtrueis converted to U+0001 START OF HEADING
The committee wasn't open to having this in the standard, but it seemed like implementers were interested in adding a compiler warning that is enabled by default here. The conversions from bool to char is semantically quite nonsensical (unless char is abused a general integer type), and leads to bugs such as the one shown in the example.