[clang-tools-extra] [clang-tidy] perf-str-view-conv improvement: support c_str/data fixing (PR #181473)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 19 13:59:23 PST 2026


vbvictor wrote:

> Well, I forgot that such pattern can be intentional for trimming the string until first `\0`:
> 
> ```c++
>     std::string_view sv("123\0""456", 7);
>     assert(sv.size() == strlen(std::string(sv).c_str())); // 7 vs 3
> ```
> 
> As a workaround I can add an option to disable fixing such patterns while still warning. WDYT?

I'm not sure how widely used this pattern is.
If anyone want such behavior, can they create a remporary variable to cleary indicate the intent?

Or you already need this option for your codebase? I'm fine if we do off-by-default option.

https://github.com/llvm/llvm-project/pull/181473


More information about the cfe-commits mailing list