[PATCH] D54943: WIP [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

Jonas Toth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 9 06:02:51 PDT 2020


JonasToth marked 2 inline comments as done.
JonasToth added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt:37
+  clangLex
+  clangSerialization
   clangTidy
----------------
aaron.ballman wrote:
> Why do serialization and lex need to be pulled in?
Thats a good question 🤔 
Probably old artifact from where everything was done here.
Removed everything except analysis


================
Comment at: clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp:46
+
+void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
+  const auto ConstType = hasType(isConstQualified());
----------------
aaron.ballman wrote:
> Should this check only fire in C++? I'm sort of on the fence. It's a C++ core guideline, so it stands to reason it should be disabled for C code. But const-correctness is a thing in C too. WDYT?
I do not know all the subtle differences between C and C++ here. Judging from this: https://stackoverflow.com/questions/5248571/is-there-const-in-c the current form would not be correct for C for pointers.
The assumptions of this check and especially the transformations are done for C++. I dont see a reason why the value-semantic would not apply for both.

Maybe there is a way to make the code compatible for both languages. The easiest solution would probably to not do the 'pointer-as-value' transformation. This is not that relevant as a feature anyway. I expect not nearly as much usage of this option as for the others.

In the end of the day i would like to support both C and C++. Right now it is untested and especially the transformation might break the code. It should run on both languages though, as there is no language checking.
I will add some real world C code-bases for the transformation testing and see what happens :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54943/new/

https://reviews.llvm.org/D54943



More information about the cfe-commits mailing list