[PATCH] D21036: Misplaced const-qualification with typedef types

Samuel Benzaquen via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 6 13:03:13 PDT 2016


sbenza added a comment.

I think this would be more interesting with macros.
Eg triggering in code like this:

  #define FOO(type, op) const type& X = op()
  FOO(int*, bar);


================
Comment at: clang-tidy/misc/MisplacedConstCheck.cpp:32
@@ +31,3 @@
+
+static QualType GuessAlternateQualification(ASTContext &Context, QualType QT) {
+  // We're given a QualType from a typedef where the qualifiers apply to the
----------------
guessAlternateQualification (lower case)

================
Comment at: test/clang-tidy/misc-misplaced-const.c:20
@@ +19,3 @@
+  const volatile ip i4 = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 'i4' declared with a const-qualified typedef type; results in the type being 'int *const volatile' instead of 'const int *volatile'
+}
----------------
If we are guessing that 'const' goes to the int, shouldn't we guess that volatile also goes to the int?

================
Comment at: test/clang-tidy/misc-misplaced-const.c:20
@@ +19,3 @@
+  const volatile ip i4 = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 'i4' declared with a const-qualified typedef type; results in the type being 'int *const volatile' instead of 'const int *volatile'
+}
----------------
sbenza wrote:
> If we are guessing that 'const' goes to the int, shouldn't we guess that volatile also goes to the int?
Only keep the first instance with the full message.
The rest can be collapsed with {{.*}} to try to fit in 80 cols.

================
Comment at: test/clang-tidy/misc-misplaced-const.cpp:20
@@ +19,3 @@
+
+template <typename Ty>
+struct S {
----------------
I assume this check does not trigger for 'const X&' where X is a pointer.
Please add a test for that.


http://reviews.llvm.org/D21036





More information about the cfe-commits mailing list