[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
Mon Apr 6 01:51:04 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE LINT COMMENT: clang-tidy-->


:warning: C/C++ code linter, clang-tidy found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

```bash

git diff -U0 origin/main...HEAD -- clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp |
python3 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py   -path build -p1 -quiet
```

</details>

<details>
<summary>
View the output from clang-tidy here.
</summary>

```
clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp:112:9: warning: variable 'VarType' of type 'QualType' can be declared 'const' [misc-const-correctness]
  112 |         QualType VarType = VD->getType();
      |         ^
      |                  const 
clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp:114:11: warning: variable 'PointeeType' of type 'QualType' can be declared 'const' [misc-const-correctness]
  114 |           QualType PointeeType = VarType->getPointeeType();
      |           ^
      |                    const 
clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp:118:9: warning: variable 'CastType' of type 'QualType' can be declared 'const' [misc-const-correctness]
  118 |         QualType CastType = ICE->getType();
      |         ^
      |                  const 
clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp:120:11: warning: variable 'PointeeType' of type 'QualType' can be declared 'const' [misc-const-correctness]
  120 |           QualType PointeeType = CastType->getPointeeType();
      |           ^
      |                    const 
clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp:124:9: warning: variable 'CastType' of type 'QualType' can be declared 'const' [misc-const-correctness]
  124 |         QualType CastType = Cast->getType();
      |         ^
      |                  const 
clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp:126:11: warning: variable 'PointeeType' of type 'QualType' can be declared 'const' [misc-const-correctness]
  126 |           QualType PointeeType = CastType->getPointeeType();
      |           ^
      |                    const 
clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp:161:3: warning: variable 'Description' of type 'llvm::StringRef' can be declared 'const' [misc-const-correctness]
  161 |   llvm::StringRef Description = UseCStr
      |   ^
      |                   const
```

</details>


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


More information about the cfe-commits mailing list