[clang-tools-extra] [clang-tidy] Add readability-stringview-substr check (PR #120055)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 21 03:34:07 PST 2026
https://github.com/zeyi2 commented:
It may be nice to add notes about boundary safety in the documentation.
-----
https://en.cppreference.com/w/cpp/string/basic_string_view/remove_suffix.html
> If n > size() is true, the behavior is undefined.
If I understand the current implementation correctly, we may have fixes like:
```cpp
std::string_view sv = "Hi";
size_t n = 5;
sv = sv.substr(0, sv.size() - n);
// ->
// sv.remove_suffix(n); // UB
```
https://github.com/llvm/llvm-project/pull/120055
More information about the cfe-commits
mailing list