[clang-tools-extra] r283873 - [clang-tidy] readability-avoid-const-params-in-decls template instantiation bugfix

Malcolm Parsons via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 11 05:02:17 PDT 2016


Author: malcolm.parsons
Date: Tue Oct 11 07:02:16 2016
New Revision: 283873

URL: http://llvm.org/viewvc/llvm-project?rev=283873&view=rev
Log:
[clang-tidy] readability-avoid-const-params-in-decls template instantiation bugfix

Summary: Bugfix for 30398.  Don't warn for template instantiations

Reviewers: aaron.ballman, hokein, alexfh

Subscribers: omtcyfz, cfe-commits

Differential Revision: https://reviews.llvm.org/D24652

Modified:
    clang-tools-extra/trunk/clang-tidy/readability/AvoidConstParamsInDecls.cpp
    clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp

Modified: clang-tools-extra/trunk/clang-tidy/readability/AvoidConstParamsInDecls.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/AvoidConstParamsInDecls.cpp?rev=283873&r1=283872&r2=283873&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/AvoidConstParamsInDecls.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/AvoidConstParamsInDecls.cpp Tue Oct 11 07:02:16 2016
@@ -36,7 +36,12 @@ void AvoidConstParamsInDecls::registerMa
       functionDecl(unless(isDefinition()),
                    // Lambdas are always their own definition, but they
                    // generate a non-definition FunctionDecl too. Ignore those.
-                   unless(cxxMethodDecl(ofClass(cxxRecordDecl(isLambda())))),
+                   // Class template instantiations have a non-definition
+                   // CXXMethodDecl for methods that aren't used in this
+                   // translation unit. Ignore those, as the template will have
+                   // already been checked.
+                   unless(cxxMethodDecl(ofClass(cxxRecordDecl(anyOf(
+                       isLambda(), ast_matchers::isTemplateInstantiation()))))),
                    has(typeLoc(forEach(ConstParamDecl))))
           .bind("func"),
       this);

Modified: clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp?rev=283873&r1=283872&r2=283873&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-avoid-const-params-in-decls.cpp Tue Oct 11 07:02:16 2016
@@ -53,6 +53,12 @@ void F12(const bool b = true);
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: parameter 'b'
 // CHECK-FIXES: void F12(bool b = true);
 
+template<class T>
+int F13(const bool b = true);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'b'
+// CHECK-FIXES: int F13(bool b = true);
+int f13 = F13<int>();
+
 struct Foo {
   Foo(const int i);
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: parameter 'i'
@@ -63,6 +69,18 @@ struct Foo {
   // CHECK-FIXES: void operator()(int i);
 };
 
+template <class T>
+struct FooT {
+  FooT(const int i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: parameter 'i'
+  // CHECK-FIXES: FooT(int i);
+
+  void operator()(const int i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i'
+  // CHECK-FIXES: void operator()(int i);
+};
+FooT<int> f(1);
+
 // Do not match on definitions
 void NF1(const int i) {}
 void NF2(const int *const i) {}
@@ -72,6 +90,25 @@ void NF5(const int) {}
 void NF6(const int *const) {}
 void NF7(int, const int) {}
 void NF8(const int, const int) {}
+template <class T>
+int NF9(const int, const int) { return 0; }
+int nf9 = NF9<int>(1, 2);
+
+// Do not match on inline member functions
+struct Bar {
+  Bar(const int i) {}
+
+  void operator()(const int i) {}
+};
+
+// Do not match on inline member functions of a templated class
+template <class T>
+struct BarT {
+  BarT(const int i) {}
+
+  void operator()(const int i) {}
+};
+BarT<int> b(1);
 
 // Do not match on other stuff
 void NF(const alias_type& i);




More information about the cfe-commits mailing list