[clang-tools-extra] [clang-tidy] Enhance container-data-pointer-check to suggest `c_str` for consts (PR #190590)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 9 04:57:25 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.h clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp b/clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
index a2ca31f15..6d5f06e4f 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
@@ -86,7 +86,7 @@ void ContainerDataPointerCheck::registerMatchers(MatchFinder *Finder) {
this);
}
-static bool isContainerConst(const Expr* ContainerExpr) {
+static bool isContainerConst(const Expr *ContainerExpr) {
QualType ContainerType = ContainerExpr->getType();
if (ContainerType->isPointerType())
ContainerType = ContainerType->getPointeeType();
@@ -118,7 +118,7 @@ static bool shouldUseCStr(const MatchFinder::MatchResult &Result) {
if (isConstPointer(Cast->getType()))
return true;
} else if (const auto *RetStmt = Parents[0].get<ReturnStmt>()) {
- const Expr* RetValue = RetStmt->getRetValue();
+ const Expr *RetValue = RetStmt->getRetValue();
if (isConstPointer(RetValue->getType()))
return true;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/190590
More information about the cfe-commits
mailing list