Page MenuHomePhabricator

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

Authored by mgartmann on Apr 21 2021, 9:55 AM.



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 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!

Diff Detail

Event Timeline

mgartmann created this revision.Apr 21 2021, 9:55 AM
mgartmann requested review of this revision.Apr 21 2021, 9:55 AM
mgartmann updated this revision to Diff 339565.Apr 22 2021, 4:44 AM
  • Renamed printCleanedType() to cleanType()
  • Extended cleanType() to also remove (anonymous) from a type
  • Made hasSpaceAfterType() more error-robust.
mgartmann updated this revision to Diff 339574.Apr 22 2021, 5:20 AM

Fixed one-off error.

mgartmann updated this revision to Diff 341155.Apr 28 2021, 5:17 AM

Replaced string comparison to check if a character is a space with std::isspace().
Added test case for this scenario.

Friendly ping, any feedback would be appreciated :)

Dear reviewers,

Since this work was conducted as part of a Bachelor's thesis, which has to be
handed in on the 18th of June, 2021, we wanted to add a friendly ping to this

It would make us, the thesis team, proud to state that some of our work was
accepted and included into the LLVM project.

Therefore, we wanted to ask if we can further improve anything in this patch
for it to get a LGTM?

Thanks a lot in advance!
Yours faithfully,
Fabian & Marco