[clang-tools-extra] [clang-tidy] Add a new check 'performance-string-view-conversions' (PR #174288)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 10 02:16:17 PST 2026
https://github.com/zeyi2 requested changes to this pull request.
I think this check introduces a sementic change, here is a reproducer:
```
m at n:~/.../projects/llvm-project$ cat a.cpp
#include <iostream>
#include <string>
#include <string_view>
void f(std::string_view) {
std::cout << "Original behavior (string_view)" << std::endl;
}
void f(const char *) {
std::cout << "Changed behavior (const char*)" << std::endl;
}
int main() {
f(std::string("text"));
return 0;
}
m at n:~/.../projects/llvm-project$ ./build/bin/clang++ a.cpp -oa && ./a && rm a
Original behavior (string_view)
m at n:~/.../projects/llvm-project$ ./build/bin/clang-tidy a.cpp --checks="-*,performance-string-view-conversions" -fix -- -std=c++17
1 warning generated.
/home/mitchell/Documents/projects/llvm-project/a.cpp:14:5: warning: redundant conversion to 'std::string' (aka 'basic_string<char>') and then back to '__sv_type' (aka 'basic_string_view<char, std::char_traits<char>>') [performance-string-view-conversions]
14 | f(std::string("text"));
| ^~~~~~~~~~~~~~~~~~~
| "text"
/home/mitchell/Documents/projects/llvm-project/a.cpp:14:5: note: FIX-IT applied suggested code changes
clang-tidy applied 1 of 1 suggested fixes.
m at n:~/.../projects/llvm-project$ ./build/bin/clang++ a.cpp -ob && ./b && rm b
Changed behavior (const char*)
```
https://github.com/llvm/llvm-project/pull/174288
More information about the cfe-commits
mailing list