[PATCH] D72373: [clang-tidy] extend misc-misplaced-const to detect using besides typedef

Alexander Lanin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 7 16:00:42 PST 2020


AlexanderLanin added a comment.

looking at this at least many are indeed valid results: F11183407: partial-misc-misplaced-const-llvm-output.zip <https://reviews.llvm.org/F11183407>
I guess false positives could be reduced by eliminating those cases where the variables are (intentionally) modified.

FIX-IT isn't quite that obvious. Some options:

- look for other typedef which contains the same as const
- create new typedef/using
- remove "*" from typedef and adjust all usage accordingly. Implies removing "Ptr" suffix.



================
Comment at: clang-tools-extra/test/clang-tidy/checkers/misc-misplaced-const.cpp:2
+// RUN: %check_clang_tidy %s misc-misplaced-const %t -- -- -DUSING
+// RUN: %check_clang_tidy %s misc-misplaced-const %t -- -- -DTYPEDEF
+
----------------
is this good practice? I didn't want to duplicate everything here.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/misc-misplaced-const.cpp:32
+  // Potentially quite unexpectedly the int can be modified here
+  // CHECK-MESSAGES: :[[@LINE+1]]:23: warning: 'i' declared with a const-qualified {{.*}}; results in the type being 'int *const' instead of 'const int *'
+  if (const ptr_to_int i = 0) {
----------------
not sure how to remove the regex here without duplicating everything


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72373





More information about the cfe-commits mailing list