[clang-tools-extra] [clang-tidy] Improve `container-data-pointer` check to use `c_str()` (PR #71304)

via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 5 07:27:58 PST 2023


================
@@ -111,16 +115,18 @@ void ContainerDataPointerCheck::check(const MatchFinder::MatchResult &Result) {
            MemberExpr>(CE))
     ReplacementText = "(" + ReplacementText + ")";
 
-  if (CE->getType()->isPointerType())
-    ReplacementText += "->data()";
-  else
-    ReplacementText += ".data()";
+  ReplacementText += CE->getType()->isPointerType() ? "->" : ".";
+  ReplacementText += CStrMethod != NULL ? "c_str()" : "data()";
----------------
EugeneZelenko wrote:

`nullptr` or use only pointer (with implicit Boolean conversion).

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


More information about the cfe-commits mailing list