Page MenuHomePhabricator

[clang-tidy] Add clang tidy check I.2 to cppcoreguidelines
Needs ReviewPublic

Authored by vingeldal on Thu, Nov 14, 11:32 AM.

Details

Summary

Cpp Core Guideline I.2, a.k.a "Avoid non-const global variables"
For detailed documentation, see:
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#i2-avoid-non-const-global-variables

Event Timeline

vingeldal created this revision.Thu, Nov 14, 11:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptThu, Nov 14, 11:32 AM
JonasToth added inline comments.Thu, Nov 14, 5:11 PM
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
20

This matcher already exists either as global matcher or in some other check. please refactor it out.

39

const fixing is a complicated issue. I would rather not do this now, as there is currently a patch in flight that does the general case.
If you really want it, there is a util for that in clang-tidy/util/ that is able to do some const-fixing.

clang-tools-extra/docs/ReleaseNotes.rst
97

Please describe the check with one sentence and sync that with the check documentation.

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-non-const-global-variables.rst
6

Please adjust the documentation here as well :)

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
3

Please add test-cases for pointers and references of builtins (int and the like) and classes/structs/enums/unions, function pointers and member function/data pointers.
We need to consider template variables as well (i think a c++14 feature).

I am not sure about the consteval support in clang for c++20, but for each feature from a newer standard its better to have a additional test-file that will use this standard.

Hi vingeldal,

thanks for you contribution and welcome to LLVM :)
If you have any questions or the like, feel free to ask!

Best Regards, Jonas