[clang-tools-extra] [clang-tidy] Also check string_view in bugprone-string-literal-with-embedded-nul (PR #234722)
Zeyi Xu via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 15 16:44:23 PST 2026
================
@@ -35,15 +35,16 @@ void StringLiteralWithEmbeddedNulCheck::registerMatchers(MatchFinder *Finder) {
const auto StrLitWithNul =
ignoringParenImpCasts(stringLiteral(containsNul()).bind("truncated"));
- // Match string constructor.
- const auto StringConstructorExpr = expr(anyOf(
- cxxConstructExpr(argumentCountIs(1),
- hasDeclaration(cxxMethodDecl(hasName("basic_string")))),
- // If present, the second argument is the alloc object which must not
- // be present explicitly.
- cxxConstructExpr(argumentCountIs(2),
- hasDeclaration(cxxMethodDecl(hasName("basic_string"))),
- hasArgument(1, cxxDefaultArgExpr()))));
+ // Match string and string-view constructors.
+ const auto StringConstructorExpr = expr(
+ anyOf(cxxConstructExpr(argumentCountIs(1),
+ hasDeclaration(cxxMethodDecl(hasAnyName(
+ "basic_string", "basic_string_view")))),
----------------
zeyi2 wrote:
Nit:
```c++
hasDeclaration(cxxConstructorDecl(
ofClass(cxxRecordDecl(hasName("::std::basic_string_view")))))
```
Could we restrict this matcher to `std::basic_string_view` only to `std::`?
https://github.com/llvm/llvm-project/pull/234722
More information about the cfe-commits
mailing list