[clang:frontend] Feature request: warn when converting `bool` to a character type (P3765R0)
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Hey, I recently presented https://github.com/cplusplus/papers/issues/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:
```cpp
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:
- `false` is converted to U+0000 NULL
- `true` is 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.
Contributor guide
Research direction
Start with the P3765R0 paper and the bool-to-character example in the issue, then inspect Clang's frontend diagnostics and tests for existing conversion warnings. Done means a default-enabled warning reliably identifies implicit bool-to-character conversions, with behavior and diagnostic coverage validated by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100