[clang-tools-extra] [clang-tidy] Add a new check 'modernize-use-string-view' (PR #172170)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 23 23:26:14 PST 2025
================
@@ -16,13 +17,13 @@ using namespace clang::ast_matchers;
namespace clang::tidy::modernize {
static StringRef toStringViewTypeStr(StringRef Type) {
- if (Type.contains("wchar_t"))
+ if (Type.contains("wchar_t") || Type.ends_with("wstring"))
return "std::wstring_view";
- if (Type.contains("char8_t"))
+ if (Type.contains("char8_t") || Type.ends_with("u8string"))
return "std::u8string_view";
- if (Type.contains("char16_t"))
+ if (Type.contains("char16_t") || Type.ends_with("u16string"))
return "std::u16string_view";
- if (Type.contains("char32_t"))
+ if (Type.contains("char32_t") || Type.ends_with("u32string"))
----------------
vbvictor wrote:
Can we make a separate test with mocks that mimic stdlib behavior in Chromium? Otherwise, someone could refactor this check and break it's "undocumented" behavoir.
Could you use `getReturnType().getUnqualifiedDesugaredType()`, it should produce `basic_string<...>`.
https://github.com/llvm/llvm-project/pull/172170
More information about the cfe-commits
mailing list