[PATCH] D100972: [clang-tidy] cppcoreguidelines-avoid-non-const-global-variables: add fixes to checks

Marco Gartmann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 21 09:55:26 PDT 2021


mgartmann created this revision.
mgartmann added reviewers: aaron.ballman, njames93, alexfh.
mgartmann added a project: clang-tools-extra.
Herald added subscribers: shchenz, kbarton, xazax.hun, nemanjai.
mgartmann requested review of this revision.

I added fixes to the existing checks of `cppcoreguidelines-avoid-non-const-global-variables`.

To fix the `non-const_variable` case, it utilizes QualType::addConst <https://clang.llvm.org/doxygen/classclang_1_1QualType.html#a43a8b5d4a9d63c319ad978252426379a> to make the non-const type constant.

For the `indirection_to_non-const` case, for the sake of simplicity of this check, the `const` keyword is simply inserted at the variable declaration's beginning. If someone knows a more elegant solution to this, I am happy to adapt it.

Thanks in advance for any feedback!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100972

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-non-const-global-variables.rst
  clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100972.339256.patch
Type: text/x-patch
Size: 24950 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210421/d0090348/attachment-0001.bin>


More information about the cfe-commits mailing list