[PATCH] D113148: Add new clang-tidy check for string_view(nullptr)

CJ Johnson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 8 09:20:30 PST 2021

CJ-Johnson added inline comments.

Comment at: clang-tools-extra/test/clang-tidy/checkers/bugprone-stringview-nullptr.cpp:84
+    (void)(std::string_view({nullptr})) /* a3 */;
+    // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor
CJ-Johnson wrote:
> aaron.ballman wrote:
> > This (and many others) also generates `-Wbraced-scalar-init`, is that intentional?
> My goal was just to be thorough in the cases tested. It's not an endorsement of the source patterns. :)
As a followup to this: I've added additional test cases and a minor change to the AST matchers to catch another form of the `-Wbraced-scalar-init` pattern.

This: `accepts_string_view({{}});`

This pattern will select the `const CharT*` constructor overload and then value-initialize the argument, causing a null deref. It happens to not include the `nullptr` literal but it has the exact same effect as `accepts_string_view(nullptr);` and `accepts_string_view({nullptr});`

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list