Re: [PATCH] D16854: [clang-tidy] Fix a crash issue on misc-virtual-near-miss check.

2016-02-03 Thread Cong Liu via cfe-commits
congliu accepted this revision.
congliu added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks!


Repository:
  rL LLVM

http://reviews.llvm.org/D16854



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16922: [clang-tidy] Added check-fixes for misc-virtual-near-miss.

2016-02-05 Thread Cong Liu via cfe-commits
congliu created this revision.
congliu added a reviewer: alexfh.
congliu added a subscriber: cfe-commits.

Addes FixItHint and updated test.

http://reviews.llvm.org/D16922

Files:
  clang-tidy/misc/VirtualNearMissCheck.cpp
  test/clang-tidy/misc-virtual-near-miss.cpp

Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- test/clang-tidy/misc-virtual-near-miss.cpp
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -16,16 +16,19 @@
   // overriden by this class.
   virtual void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::funk' has a 
similar name and the same signature as virtual method 'Base::func'; did you 
mean to override it? [misc-virtual-near-miss]
+  // CHECK-FIXES: virtual void func();
 
   void func2();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::func2' has 
{{.*}} 'Base::func'
+  // CHECK-FIXES: void func();
 
   void func22(); // Should not warn.
 
   void gunk(); // Should not warn: gunk is override.
 
   void fun();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::fun' has {{.*}} 
'Base::func'
+  // CHECK-FIXES: void func();
 
   Derived &operator==(const Base &); // Should not warn: operators are ignored.
 
@@ -58,32 +61,40 @@
 
   virtual void func2();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::func2' has {{.*}} 
'Father::func'
+  // CHECK-FIXES: virtual void func();
 
   int methoe(int x, char **strs); // Should not warn: parameter types don't 
match.
 
   int methoe(int x);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::methoe' has 
{{.*}} 'Mother::method'
+  // CHECK-FIXES: int method(int x);
 
   void methof(int x, const char **strs); // Should not warn: return types 
don't match.
 
   int methoh(int x, const char **strs);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::methoh' has 
{{.*}} 'Mother::method'
+  // CHECK-FIXES: int method(int x, const char **strs);
 
   virtual Child *creat(int i);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::creat' has {{.*}} 
'Father::create'
+  // CHECK-FIXES: virtual Child *create(int i);
 
   virtual Derived &&generat();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::generat' has 
{{.*}} 'Father::generate'
+  // CHECK-FIXES: virtual Derived &&generate();
 
   int decaz(const char str[]);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::decaz' has {{.*}} 
'Mother::decay'
+  // CHECK-FIXES: int decay(const char str[]);
 
   operator bool();
 
   derived_type *canonica(derived_type D);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::canonica' has 
{{.*}} 'Father::canonical'
+  // CHECK-FIXES: derived_type *canonical(derived_type D);
 
 private:
   void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::funk' has {{.*}} 
'Father::func'
+  // CHECK-FIXES: void func();
 };
Index: clang-tidy/misc/VirtualNearMissCheck.cpp
===
--- clang-tidy/misc/VirtualNearMissCheck.cpp
+++ clang-tidy/misc/VirtualNearMissCheck.cpp
@@ -249,11 +249,14 @@
 if (EditDistance > 0 && EditDistance <= EditDistanceThreshold) {
   if (checkOverrideWithoutName(Context, BaseMD, DerivedMD)) {
 // A "virtual near miss" is found.
+auto Range = CharSourceRange::getTokenRange(SourceRange(
+DerivedMD->getLocation(), DerivedMD->getLocation()));
 diag(DerivedMD->getLocStart(),
  "method '%0' has a similar name and the same signature as "
  "virtual method '%1'; did you mean to override it?")
 << DerivedMD->getQualifiedNameAsString()
-<< BaseMD->getQualifiedNameAsString();
+<< BaseMD->getQualifiedNameAsString()
+<< FixItHint::CreateReplacement(Range, BaseMD->getName());
   }
 }
   }


Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- test/clang-tidy/misc-virtual-near-miss.cpp
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -16,16 +16,19 @@
   // overriden by this class.
   virtual void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::funk' has a similar name and the same signature as virtual method 'Base::func'; did you mean to override it? [misc-virtual-near-miss]
+  // CHECK-FIXES: virtual void func();
 
   void func2();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::func2' has {{.*}} 'Base::func'
+  // CHECK-FIXES: void func();
 
   void func22(); // Should not warn.
 
   void gunk(); // Should not warn: gunk is override.
 
   void fun();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::fun' has {{.*}} 'Base::func'
+  // CHECK-FIXES: void func();
 
   Derived &operator==(const Base &); // Should not warn: operators are ignored.
 
@@ -58,32 +61,40 @@
 
   virtual void func2();

Re: [PATCH] D16922: [clang-tidy] Added check-fixes for misc-virtual-near-miss.

2016-02-05 Thread Cong Liu via cfe-commits
congliu updated this revision to Diff 47024.
congliu added a comment.

- Added test cases of macro and template.


http://reviews.llvm.org/D16922

Files:
  clang-tidy/misc/VirtualNearMissCheck.cpp
  test/clang-tidy/misc-virtual-near-miss.cpp

Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- test/clang-tidy/misc-virtual-near-miss.cpp
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -1,5 +1,25 @@
 // RUN: %check_clang_tidy %s misc-virtual-near-miss %t
 
+#define MACRO1 void funcM()
+#define MACRO2(m) void m()
+
+template 
+struct TBase {
+  virtual void tfunc(T t);
+};
+
+template 
+struct TDerived : TBase {
+  virtual void tfunk(T t);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'TDerived::tfunk' has a similar name and the same signature as virtual method 'TBase::tfunc'; did you mean to override it? [misc-virtual-near-miss]
+  // CHECK-MESSAGES: note: this fix will not be applied because it overlaps with another fix
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: method 'TDerived::tfunk' has {{.*}} 'TBase::tfunc'
+  // CHECK-MESSAGES: note: this fix will not be applied because it overlaps with another fix
+};
+
+TDerived T1;
+TDerived T2;
+
 class NoDefinedClass1;
 class NoDefinedClass2;
 
@@ -15,21 +35,31 @@
   // Should not warn "do you want to override 'gunk'?", because gunk is already
   // overriden by this class.
   virtual void funk();
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::funk' has a similar name and the same signature as virtual method 'Base::func'; did you mean to override it? [misc-virtual-near-miss]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::funk' has {{.*}} 'Base::func'
+  // CHECK-FIXES: virtual void func();
 
   void func2();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::func2' has {{.*}} 'Base::func'
+  // CHECK-FIXES: void func();
 
   void func22(); // Should not warn.
 
   void gunk(); // Should not warn: gunk is override.
 
   void fun();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::fun' has {{.*}} 'Base::func'
+  // CHECK-FIXES: void func();
 
   Derived &operator==(const Base &); // Should not warn: operators are ignored.
 
   virtual NoDefinedClass2 *f1(); // Should not crash: non-defined class return type is ignored.
+
+  MACRO1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::funcM' has {{.*}} 'Base::func'
+
+  MACRO2(func3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::func3' has {{.*}} 'Base::func'
+  // CHECK-FIXES: MACRO2(func);
 };
 
 typedef Derived derived_type;
@@ -58,32 +88,40 @@
 
   virtual void func2();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::func2' has {{.*}} 'Father::func'
+  // CHECK-FIXES: virtual void func();
 
   int methoe(int x, char **strs); // Should not warn: parameter types don't match.
 
   int methoe(int x);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::methoe' has {{.*}} 'Mother::method'
+  // CHECK-FIXES: int method(int x);
 
   void methof(int x, const char **strs); // Should not warn: return types don't match.
 
   int methoh(int x, const char **strs);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::methoh' has {{.*}} 'Mother::method'
+  // CHECK-FIXES: int method(int x, const char **strs);
 
   virtual Child *creat(int i);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::creat' has {{.*}} 'Father::create'
+  // CHECK-FIXES: virtual Child *create(int i);
 
   virtual Derived &&generat();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::generat' has {{.*}} 'Father::generate'
+  // CHECK-FIXES: virtual Derived &&generate();
 
   int decaz(const char str[]);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::decaz' has {{.*}} 'Mother::decay'
+  // CHECK-FIXES: int decay(const char str[]);
 
   operator bool();
 
   derived_type *canonica(derived_type D);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::canonica' has {{.*}} 'Father::canonical'
+  // CHECK-FIXES: derived_type *canonical(derived_type D);
 
 private:
   void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::funk' has {{.*}} 'Father::func'
+  // CHECK-FIXES: void func();
 };
Index: clang-tidy/misc/VirtualNearMissCheck.cpp
===
--- clang-tidy/misc/VirtualNearMissCheck.cpp
+++ clang-tidy/misc/VirtualNearMissCheck.cpp
@@ -249,11 +249,14 @@
 if (EditDistance > 0 && EditDistance <= EditDistanceThreshold) {
   if (checkOverrideWithoutName(Context, BaseMD, DerivedMD)) {
 // A "virtual near miss" is found.
+auto Range = CharSourceRange::getTokenRange(
+SourceRange(DerivedMD->getLocation()));
 diag(DerivedMD->getLocStart(),
  "method '%0' has a similar name and the same signature as "
  "virtual method '%1'; did you mean to ov

Re: [PATCH] D16922: [clang-tidy] Added check-fixes for misc-virtual-near-miss.

2016-02-05 Thread Cong Liu via cfe-commits
congliu added inline comments.


Comment at: test/clang-tidy/misc-virtual-near-miss.cpp:1
@@ -1,2 +1,2 @@
 // RUN: %check_clang_tidy %s misc-virtual-near-miss %t
 

alexfh wrote:
> Please add a test ensuring replacements are applied correctly in templates 
> with multiple instantiations and in macros.
Now the fixes work fine for macros. But for template, the behavior is, as the 
test shows, two warnings were generated, no fix was applied. Is this what we 
want or should we change the strategy?


http://reviews.llvm.org/D16922



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D16922: [clang-tidy] Added check-fixes for misc-virtual-near-miss.

2016-02-09 Thread Cong Liu via cfe-commits
congliu updated this revision to Diff 47307.
congliu added a comment.

- Disallowed matches for method in template instantiations. Updated test.


http://reviews.llvm.org/D16922

Files:
  clang-tidy/misc/VirtualNearMissCheck.cpp
  test/clang-tidy/misc-virtual-near-miss.cpp

Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- test/clang-tidy/misc-virtual-near-miss.cpp
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -16,22 +16,54 @@
   // overriden by this class.
   virtual void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::funk' has a similar name and the same signature as virtual method 'Base::func'; did you mean to override it? [misc-virtual-near-miss]
+  // CHECK-FIXES: virtual void func();
 
   void func2();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::func2' has {{.*}} 'Base::func'
+  // CHECK-FIXES: void func();
 
   void func22(); // Should not warn.
 
   void gunk(); // Should not warn: gunk is override.
 
   void fun();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::fun' has {{.*}} 'Base::func'
+  // CHECK-FIXES: void func();
 
   Derived &operator==(const Base &); // Should not warn: operators are ignored.
 
   virtual NoDefinedClass2 *f1(); // Should not crash: non-defined class return type is ignored.
 };
 
+template 
+struct TBase {
+  virtual void tfunc(T t);
+};
+
+template 
+struct TDerived : TBase {
+  virtual void tfunk(T t);
+  // Should not warn for 'TDerived::tfunk' or 'TDerived::tfunk',
+  // because matches in template instantiations are ignored.
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: method 'TDerived::tfunk' has {{.*}} 'TBase::tfunc'
+  // CHECK-FIXES: virtual void tfunc(T t);
+};
+
+TDerived T1;
+TDerived T2;
+
+// Should not fix macro definition
+#define MACRO1 void funcM()
+#define MACRO2(m) void m()
+struct DerivedMacro : Base {
+  MACRO1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'DerivedMacro::funcM' has {{.*}} 'Base::func'
+
+  MACRO2(func3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'DerivedMacro::func3' has {{.*}} 'Base::func'
+  // CHECK-FIXES: MACRO2(func);
+};
+
 typedef Derived derived_type;
 
 class Father {
@@ -58,32 +90,40 @@
 
   virtual void func2();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::func2' has {{.*}} 'Father::func'
+  // CHECK-FIXES: virtual void func();
 
   int methoe(int x, char **strs); // Should not warn: parameter types don't match.
 
   int methoe(int x);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::methoe' has {{.*}} 'Mother::method'
+  // CHECK-FIXES: int method(int x);
 
   void methof(int x, const char **strs); // Should not warn: return types don't match.
 
   int methoh(int x, const char **strs);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::methoh' has {{.*}} 'Mother::method'
+  // CHECK-FIXES: int method(int x, const char **strs);
 
   virtual Child *creat(int i);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::creat' has {{.*}} 'Father::create'
+  // CHECK-FIXES: virtual Child *create(int i);
 
   virtual Derived &&generat();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::generat' has {{.*}} 'Father::generate'
+  // CHECK-FIXES: virtual Derived &&generate();
 
   int decaz(const char str[]);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::decaz' has {{.*}} 'Mother::decay'
+  // CHECK-FIXES: int decay(const char str[]);
 
   operator bool();
 
   derived_type *canonica(derived_type D);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::canonica' has {{.*}} 'Father::canonical'
+  // CHECK-FIXES: derived_type *canonical(derived_type D);
 
 private:
   void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::funk' has {{.*}} 'Father::func'
+  // CHECK-FIXES: void func();
 };
Index: clang-tidy/misc/VirtualNearMissCheck.cpp
===
--- clang-tidy/misc/VirtualNearMissCheck.cpp
+++ clang-tidy/misc/VirtualNearMissCheck.cpp
@@ -178,6 +178,50 @@
   return false;
 }
 
+/// Get declaration given the type of a class (including template class).
+///
+/// This function is copied from the one defined in ASTMatchFinder.cpp to solve
+/// the problem that QualType::getAsCXXRecordDecl does not work for template
+/// class.
+static CXXRecordDecl *getAsCXXRecordDecl(const Type *TypeNode) {
+  if (TypeNode->getAs() != nullptr ||
+  TypeNode->getAs() != nullptr ||
+  TypeNode->getAs() != nullptr)
+// Dependent names and template TypeNode parameters will be matched when the
+// template is instantiated.
+return nullptr;
+  TemplateSpecializationType const *TemplateType =
+  TypeNode->getAs();
+  if (!TemplateType)
+return TypeNode->getAsCXXRecordDecl();
+
+  if (TemplateType->getTemplateName().isDependent())
+// Dependent template specializations will be matched when the template is
+// 

Need to use function "getAsCXXRecordDecl" of ASTMatchFinder.cpp in a clang-tidy check

2016-02-09 Thread Cong Liu via cfe-commits
Hi Richard,

I need to use the function (line 747 of ASTMatchFinder.cpp
):

  static CXXRecordDecl *getAsCXXRecordDecl(const Type *TypeNode)

in the misc-virtual-near-miss check of clang-tidy, because it can correctly
get the declaration of a template type, while QualType::getAsCXXRecordDecl
cannot.

But this function is not accessible in clang-tidy check. I think we should
make this function public accessible since its useful. Could you please
tell me how to do it? Thanks a lot.

Best regards,
Cong
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: Need to use function "getAsCXXRecordDecl" of ASTMatchFinder.cpp in a clang-tidy check

2016-02-09 Thread Cong Liu via cfe-commits
Hi Richard,

Thank you for your reply. Yes, the case I need to deal with is like what
you said:

> If you want to make the assumption that the primary template will be
> used for an unknown specialization, you'll need something like that
> function in ASTMatchFinder.


For example,


   1.   template 
   2.   struct Base {};
   3.   template 
   4.   struct Derived : Base{};
   5.
   6.   Derived T1;

In this case, I need to firstly get the CXXBaseSpecifier from line 4, then
get the QualType of primary template (Base), then get its declaration.
For this case, that function in ASTMatchFinder works but
Type::getAsCXXRecordDecl does not.

So, what do you suggest?

Best regards,
Cong
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D16922: [clang-tidy] Added check-fixes for misc-virtual-near-miss.

2016-02-10 Thread Cong Liu via cfe-commits
congliu updated this revision to Diff 47448.
congliu marked 2 inline comments as done.
congliu added a comment.

- Generate a single warning for multiple template instantiations.


http://reviews.llvm.org/D16922

Files:
  clang-tidy/misc/VirtualNearMissCheck.cpp
  clang-tidy/misc/VirtualNearMissCheck.h
  test/clang-tidy/misc-virtual-near-miss.cpp

Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- test/clang-tidy/misc-virtual-near-miss.cpp
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -16,22 +16,57 @@
   // overriden by this class.
   virtual void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::funk' has a similar name and the same signature as virtual method 'Base::func'; did you mean to override it? [misc-virtual-near-miss]
+  // CHECK-FIXES: virtual void func();
 
   void func2();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::func2' has {{.*}} 'Base::func'
+  // CHECK-FIXES: void func();
 
   void func22(); // Should not warn.
 
   void gunk(); // Should not warn: gunk is override.
 
   void fun();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::fun' has {{.*}} 'Base::func'
+  // CHECK-FIXES: void func();
 
   Derived &operator==(const Base &); // Should not warn: operators are ignored.
 
   virtual NoDefinedClass2 *f1(); // Should not crash: non-defined class return type is ignored.
 };
 
+template 
+struct TBase {
+  virtual void tfunc(T t);
+};
+
+template 
+struct TDerived : TBase {
+  virtual void tfunk(T t);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'TDerived::tfunk' has {{.*}} 'TBase::tfunc'
+  // CHECK-FIXES: struct TDerived : TBase {
+  // CHECK-FIXES-NEXT: virtual void tfunc(T t);
+};
+
+TDerived T1;
+TDerived T2;
+
+// Should not fix macro definition
+#define MACRO1 void funcM()
+// CHECK-FIXES: #define MACRO1 void funcM()
+#define MACRO2(m) void m()
+// CHECK-FIXES: #define MACRO2(m) void m()
+
+struct DerivedMacro : Base {
+  MACRO1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'DerivedMacro::funcM' has {{.*}} 'Base::func'
+  // CHECK-FIXES: MACRO1;
+
+  MACRO2(func3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'DerivedMacro::func3' has {{.*}} 'Base::func'
+  // CHECK-FIXES: MACRO2(func);
+};
+
 typedef Derived derived_type;
 
 class Father {
@@ -58,32 +93,40 @@
 
   virtual void func2();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::func2' has {{.*}} 'Father::func'
+  // CHECK-FIXES: virtual void func();
 
   int methoe(int x, char **strs); // Should not warn: parameter types don't match.
 
   int methoe(int x);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::methoe' has {{.*}} 'Mother::method'
+  // CHECK-FIXES: int method(int x);
 
   void methof(int x, const char **strs); // Should not warn: return types don't match.
 
   int methoh(int x, const char **strs);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::methoh' has {{.*}} 'Mother::method'
+  // CHECK-FIXES: int method(int x, const char **strs);
 
   virtual Child *creat(int i);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::creat' has {{.*}} 'Father::create'
+  // CHECK-FIXES: virtual Child *create(int i);
 
   virtual Derived &&generat();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::generat' has {{.*}} 'Father::generate'
+  // CHECK-FIXES: virtual Derived &&generate();
 
   int decaz(const char str[]);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::decaz' has {{.*}} 'Mother::decay'
+  // CHECK-FIXES: int decay(const char str[]);
 
   operator bool();
 
   derived_type *canonica(derived_type D);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::canonica' has {{.*}} 'Father::canonical'
+  // CHECK-FIXES: derived_type *canonical(derived_type D);
 
 private:
   void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::funk' has {{.*}} 'Father::func'
+  // CHECK-FIXES: void func();
 };
Index: clang-tidy/misc/VirtualNearMissCheck.h
===
--- clang-tidy/misc/VirtualNearMissCheck.h
+++ clang-tidy/misc/VirtualNearMissCheck.h
@@ -12,7 +12,7 @@
 
 #include "../ClangTidy.h"
 #include 
-#include 
+#include 
 
 namespace clang {
 namespace tidy {
@@ -46,7 +46,7 @@
   bool isOverriddenByDerivedClass(const CXXMethodDecl *BaseMD,
   const CXXRecordDecl *DerivedRD);
 
-  /// key: the unique ID of a method;
+  /// key: the unique ID of a method
   /// value: whether the method is possible to be overridden.
   std::map PossibleMap;
 
@@ -56,6 +56,9 @@
   std::map, bool>
   OverriddenMap;
 
+  /// key: the source location id of a generated warning
+  std::unordered_set WarningSet;
+
   const unsigned EditDistanceThreshold = 1;
 };
 
Index: clang-tidy/misc/VirtualNearMissCheck.cpp
===
--- clang-tidy/misc/VirtualNear

Re: [PATCH] D16922: [clang-tidy] Added check-fixes for misc-virtual-near-miss.

2016-02-10 Thread Cong Liu via cfe-commits
congliu added a comment.

The strategy has changed. Now this check does not ignore template in 
instantiation, instead, it generate a single warning for some instantiation and 
ignore others, so that fix is able to apply.
We do this to walk around the function copied from ASTMatchFinder, since it's 
incorrect for some tricky situation. And make sense to analyse overriding only 
when there is fully instantiation of the primary template.


http://reviews.llvm.org/D16922



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D16922: [clang-tidy] Added check-fixes for misc-virtual-near-miss.

2016-02-10 Thread Cong Liu via cfe-commits
congliu updated this revision to Diff 47461.
congliu marked 3 inline comments as done.
congliu added a comment.

- Allowed warnings but disallowed fix for template instantiations.
- Updated tests.


http://reviews.llvm.org/D16922

Files:
  clang-tidy/misc/VirtualNearMissCheck.cpp
  clang-tidy/misc/VirtualNearMissCheck.h
  test/clang-tidy/misc-virtual-near-miss.cpp

Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- test/clang-tidy/misc-virtual-near-miss.cpp
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -16,22 +16,58 @@
   // overriden by this class.
   virtual void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::funk' has a similar name and the same signature as virtual method 'Base::func'; did you mean to override it? [misc-virtual-near-miss]
+  // CHECK-FIXES: virtual void func();
 
   void func2();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::func2' has {{.*}} 'Base::func'
+  // CHECK-FIXES: void func();
 
   void func22(); // Should not warn.
 
   void gunk(); // Should not warn: gunk is override.
 
   void fun();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::fun' has {{.*}} 'Base::func'
+  // CHECK-FIXES: void func();
 
   Derived &operator==(const Base &); // Should not warn: operators are ignored.
 
   virtual NoDefinedClass2 *f1(); // Should not crash: non-defined class return type is ignored.
 };
 
+template 
+struct TBase {
+  virtual void tfunc(T t);
+};
+
+template 
+struct TDerived : TBase {
+  virtual void tfunk(T t);
+  // Should not apply fix for template.
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: method 'TDerived::tfunk' has {{.*}} 'TBase::tfunc'
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: method 'TDerived::tfunk' has {{.*}} 'TBase::tfunc'
+  // CHECK-FIXES: virtual void tfunk(T t);
+};
+
+TDerived T1;
+TDerived T2;
+
+// Should not fix macro definition
+#define MACRO1 void funcM()
+// CHECK-FIXES: #define MACRO1 void funcM()
+#define MACRO2(m) void m()
+// CHECK-FIXES: #define MACRO2(m) void m()
+
+struct DerivedMacro : Base {
+  MACRO1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'DerivedMacro::funcM' has {{.*}} 'Base::func'
+  // CHECK-FIXES: MACRO1;
+
+  MACRO2(func3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'DerivedMacro::func3' has {{.*}} 'Base::func'
+  // CHECK-FIXES: MACRO2(func);
+};
+
 typedef Derived derived_type;
 
 class Father {
@@ -58,32 +94,40 @@
 
   virtual void func2();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::func2' has {{.*}} 'Father::func'
+  // CHECK-FIXES: virtual void func();
 
   int methoe(int x, char **strs); // Should not warn: parameter types don't match.
 
   int methoe(int x);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::methoe' has {{.*}} 'Mother::method'
+  // CHECK-FIXES: int method(int x);
 
   void methof(int x, const char **strs); // Should not warn: return types don't match.
 
   int methoh(int x, const char **strs);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::methoh' has {{.*}} 'Mother::method'
+  // CHECK-FIXES: int method(int x, const char **strs);
 
   virtual Child *creat(int i);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::creat' has {{.*}} 'Father::create'
+  // CHECK-FIXES: virtual Child *create(int i);
 
   virtual Derived &&generat();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::generat' has {{.*}} 'Father::generate'
+  // CHECK-FIXES: virtual Derived &&generate();
 
   int decaz(const char str[]);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::decaz' has {{.*}} 'Mother::decay'
+  // CHECK-FIXES: int decay(const char str[]);
 
   operator bool();
 
   derived_type *canonica(derived_type D);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::canonica' has {{.*}} 'Father::canonical'
+  // CHECK-FIXES: derived_type *canonical(derived_type D);
 
 private:
   void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::funk' has {{.*}} 'Father::func'
+  // CHECK-FIXES: void func();
 };
Index: clang-tidy/misc/VirtualNearMissCheck.h
===
--- clang-tidy/misc/VirtualNearMissCheck.h
+++ clang-tidy/misc/VirtualNearMissCheck.h
@@ -12,7 +12,6 @@
 
 #include "../ClangTidy.h"
 #include 
-#include 
 
 namespace clang {
 namespace tidy {
@@ -46,12 +45,12 @@
   bool isOverriddenByDerivedClass(const CXXMethodDecl *BaseMD,
   const CXXRecordDecl *DerivedRD);
 
-  /// key: the unique ID of a method;
-  /// value: whether the method is possible to be overridden.
+  /// Key: the unique ID of a method.
+  /// Value: whether the method is possible to be overridden.
   std::map PossibleMap;
 
-  /// key: 
-  /// value: whether the base method is overridden by some method in the derived
+  /// Key: 
+  /// Value: whether the base method is overridden by some method in the derived
 

Re: Need to use function "getAsCXXRecordDecl" of ASTMatchFinder.cpp in a clang-tidy check

2016-02-10 Thread Cong Liu via cfe-commits
Hi Richard,

You are right. Actually I just need to consider the cases that there are
full instantiations of the primary template. I have changed the strategy
and not use that function.

Thanks a lot!
Cong

On Wed, Feb 10, 2016 at 2:17 AM, Richard Smith 
wrote:

> On Tue, Feb 9, 2016 at 4:15 PM, Cong Liu  wrote:
> > Hi Richard,
> >
> > Thank you for your reply. Yes, the case I need to deal with is like what
> you
> > said:
> >>
> >> If you want to make the assumption that the primary template will be
> >> used for an unknown specialization, you'll need something like that
> >> function in ASTMatchFinder.
> >
> >
> > For example,
> >
> >   template 
> >   struct Base {};
> >   template 
> >   struct Derived : Base{};
> >
> >   Derived T1;
> >
> > In this case, I need to firstly get the CXXBaseSpecifier from line 4,
> then
> > get the QualType of primary template (Base), then get its declaration.
> > For this case, that function in ASTMatchFinder works but
> > Type::getAsCXXRecordDecl does not.
> >
> > So, what do you suggest?
>
> Using that may not be correct when analysing virtual function
> overrides. Consider this:
>
> template struct Base {
>   virtual void f(T);
> };
> template<> struct Base {
>   virtual void f();
> };
> template::value> struct Derived :
> Base {
>   virtual void f();
> };
> template struct Derived : Base {
>   virtual void f(T);
> };
>
> Here, it would be wrong to report that the Derived primary template
> fails to override a virtual function from the Base primary template,
> as the Derived primary template is actually only ever used when T ==
> void, and there's a specialization of the Base template for that case.
> I have no idea whether that's acceptable for your check.
>
> In principle, I'm fine with us moving the functionality in
> ASTMatchFinder (that I recently renamed to
> getAsCXXRecordDeclOrPrimaryTemplate to better express its purpose) to
> somewhere more central, but my concern is that most uses of it will in
> fact be subtle bugs.
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r260532 - Merge branch 'arcpatch-D16922'

2016-02-11 Thread Cong Liu via cfe-commits
Author: congliu
Date: Thu Feb 11 10:03:27 2016
New Revision: 260532

URL: http://llvm.org/viewvc/llvm-project?rev=260532&view=rev
Log:
Merge branch 'arcpatch-D16922'

Modified:
clang-tools-extra/trunk/clang-tidy/misc/VirtualNearMissCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/VirtualNearMissCheck.h
clang-tools-extra/trunk/test/clang-tidy/misc-virtual-near-miss.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/VirtualNearMissCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/VirtualNearMissCheck.cpp?rev=260532&r1=260531&r2=260532&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/VirtualNearMissCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/VirtualNearMissCheck.cpp Thu Feb 11 
10:03:27 2016
@@ -249,11 +249,19 @@ void VirtualNearMissCheck::check(const M
 if (EditDistance > 0 && EditDistance <= EditDistanceThreshold) {
   if (checkOverrideWithoutName(Context, BaseMD, DerivedMD)) {
 // A "virtual near miss" is found.
-diag(DerivedMD->getLocStart(),
- "method '%0' has a similar name and the same signature as "
- "virtual method '%1'; did you mean to override it?")
+auto Range = CharSourceRange::getTokenRange(
+SourceRange(DerivedMD->getLocation()));
+
+bool ApplyFix = !BaseMD->isTemplateInstantiation() &&
+!DerivedMD->isTemplateInstantiation();
+auto Diag =
+diag(DerivedMD->getLocStart(),
+ "method '%0' has a similar name and the same signature as 
"
+ "virtual method '%1'; did you mean to override it?")
 << DerivedMD->getQualifiedNameAsString()
 << BaseMD->getQualifiedNameAsString();
+if (ApplyFix)
+  Diag << FixItHint::CreateReplacement(Range, BaseMD->getName());
   }
 }
   }

Modified: clang-tools-extra/trunk/clang-tidy/misc/VirtualNearMissCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/VirtualNearMissCheck.h?rev=260532&r1=260531&r2=260532&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/VirtualNearMissCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/VirtualNearMissCheck.h Thu Feb 11 
10:03:27 2016
@@ -12,7 +12,6 @@
 
 #include "../ClangTidy.h"
 #include 
-#include 
 
 namespace clang {
 namespace tidy {
@@ -46,12 +45,12 @@ private:
   bool isOverriddenByDerivedClass(const CXXMethodDecl *BaseMD,
   const CXXRecordDecl *DerivedRD);
 
-  /// key: the unique ID of a method;
-  /// value: whether the method is possible to be overridden.
+  /// Key: the unique ID of a method.
+  /// Value: whether the method is possible to be overridden.
   std::map PossibleMap;
 
-  /// key: 
-  /// value: whether the base method is overridden by some method in the 
derived
+  /// Key: 
+  /// Value: whether the base method is overridden by some method in the 
derived
   /// class.
   std::map, bool>
   OverriddenMap;

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-virtual-near-miss.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-virtual-near-miss.cpp?rev=260532&r1=260531&r2=260532&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-virtual-near-miss.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-virtual-near-miss.cpp Thu Feb 
11 10:03:27 2016
@@ -16,9 +16,11 @@ struct Derived : Base {
   // overriden by this class.
   virtual void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::funk' has a 
similar name and the same signature as virtual method 'Base::func'; did you 
mean to override it? [misc-virtual-near-miss]
+  // CHECK-FIXES: virtual void func();
 
   void func2();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::func2' has 
{{.*}} 'Base::func'
+  // CHECK-FIXES: void func();
 
   void func22(); // Should not warn.
 
@@ -26,12 +28,46 @@ struct Derived : Base {
 
   void fun();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::fun' has {{.*}} 
'Base::func'
+  // CHECK-FIXES: void func();
 
   Derived &operator==(const Base &); // Should not warn: operators are ignored.
 
   virtual NoDefinedClass2 *f1(); // Should not crash: non-defined class return 
type is ignored.
 };
 
+template 
+struct TBase {
+  virtual void tfunc(T t);
+};
+
+template 
+struct TDerived : TBase {
+  virtual void tfunk(T t);
+  // Should not apply fix for template.
+  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: method 'TDerived::tfunk' 
has {{.*}} 'TBase::tfunc'
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: method 'TDerived::tfunk' 
has

Re: [PATCH] D16922: [clang-tidy] Added check-fixes for misc-virtual-near-miss.

2016-02-11 Thread Cong Liu via cfe-commits
congliu closed this revision.
congliu added a comment.

Closed by commit rL260532: Merge branch 'arcpatch-D16922' 
 (authored by congliu 
)


http://reviews.llvm.org/D16922



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D17375: Add parentheses around arithmetic in operand of '|' in llvm-dwp.cpp.

2016-02-18 Thread Cong Liu via cfe-commits
congliu created this revision.
congliu added a reviewer: bkramer.
congliu added a subscriber: cfe-commits.

Add the parenthese to make it able to build.

http://reviews.llvm.org/D17375

Files:
  tools/llvm-dwp/llvm-dwp.cpp

Index: tools/llvm-dwp/llvm-dwp.cpp
===
--- tools/llvm-dwp/llvm-dwp.cpp
+++ tools/llvm-dwp/llvm-dwp.cpp
@@ -238,7 +238,7 @@
 while (Buckets[H]) {
   assert(S != IndexEntries[Buckets[H] - 1].Signature &&
  "Duplicate type unit");
-  H = (H + ((S >> 32) & Mask) | 1) % Buckets.size();
+  H = ((H + ((S >> 32) & Mask)) | 1) % Buckets.size();
 }
 Buckets[H] = i + 1;
   }


Index: tools/llvm-dwp/llvm-dwp.cpp
===
--- tools/llvm-dwp/llvm-dwp.cpp
+++ tools/llvm-dwp/llvm-dwp.cpp
@@ -238,7 +238,7 @@
 while (Buckets[H]) {
   assert(S != IndexEntries[Buckets[H] - 1].Signature &&
  "Duplicate type unit");
-  H = (H + ((S >> 32) & Mask) | 1) % Buckets.size();
+  H = ((H + ((S >> 32) & Mask)) | 1) % Buckets.size();
 }
 Buckets[H] = i + 1;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17375: Add parentheses around arithmetic in operand of '|' in llvm-dwp.cpp.

2016-02-18 Thread Cong Liu via cfe-commits
congliu updated this revision to Diff 48301.
congliu added a comment.

- Address review comment.


http://reviews.llvm.org/D17375

Files:
  tools/llvm-dwp/llvm-dwp.cpp

Index: tools/llvm-dwp/llvm-dwp.cpp
===
--- tools/llvm-dwp/llvm-dwp.cpp
+++ tools/llvm-dwp/llvm-dwp.cpp
@@ -238,7 +238,7 @@
 while (Buckets[H]) {
   assert(S != IndexEntries[Buckets[H] - 1].Signature &&
  "Duplicate type unit");
-  H = (H + ((S >> 32) & Mask) | 1) % Buckets.size();
+  H = (H + (((S >> 32) & Mask) | 1)) % Buckets.size();
 }
 Buckets[H] = i + 1;
   }


Index: tools/llvm-dwp/llvm-dwp.cpp
===
--- tools/llvm-dwp/llvm-dwp.cpp
+++ tools/llvm-dwp/llvm-dwp.cpp
@@ -238,7 +238,7 @@
 while (Buckets[H]) {
   assert(S != IndexEntries[Buckets[H] - 1].Signature &&
  "Duplicate type unit");
-  H = (H + ((S >> 32) & Mask) | 1) % Buckets.size();
+  H = (H + (((S >> 32) & Mask) | 1)) % Buckets.size();
 }
 Buckets[H] = i + 1;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r273150 - Add -fsyntax-only to Driver/opencl.cl test.

2016-06-20 Thread Cong Liu via cfe-commits
Author: congliu
Date: Mon Jun 20 06:25:26 2016
New Revision: 273150

URL: http://llvm.org/viewvc/llvm-project?rev=273150&view=rev
Log:
Add -fsyntax-only to Driver/opencl.cl test.

Modified:
cfe/trunk/test/Driver/opencl.cl

Modified: cfe/trunk/test/Driver/opencl.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/opencl.cl?rev=273150&r1=273149&r2=273150&view=diff
==
--- cfe/trunk/test/Driver/opencl.cl (original)
+++ cfe/trunk/test/Driver/opencl.cl Mon Jun 20 06:25:26 2016
@@ -1,12 +1,12 @@
-// RUN: %clang %s
-// RUN: %clang -std=cl %s
-// RUN: %clang -std=cl1.1 %s
-// RUN: %clang -std=cl1.2 %s
-// RUN: %clang -std=cl2.0 %s
-// RUN: %clang -std=CL %s
-// RUN: %clang -std=CL1.1 %s
-// RUN: %clang -std=CL1.2 %s
-// RUN: %clang -std=CL2.0 %s
+// RUN: %clang -fsyntax-only %s
+// RUN: %clang -fsyntax-only -std=cl %s
+// RUN: %clang -fsyntax-only -std=cl1.1 %s
+// RUN: %clang -fsyntax-only -std=cl1.2 %s
+// RUN: %clang -fsyntax-only -std=cl2.0 %s
+// RUN: %clang -fsyntax-only -std=CL %s
+// RUN: %clang -fsyntax-only -std=CL1.1 %s
+// RUN: %clang -fsyntax-only -std=CL1.2 %s
+// RUN: %clang -fsyntax-only -std=CL2.0 %s
 // RUN: not %clang_cc1 -std=c99 -DOPENCL %s 2>&1 | FileCheck 
--check-prefix=CHECK-C99 %s
 // RUN: not %clang_cc1 -std=invalid -DOPENCL %s 2>&1 | FileCheck 
--check-prefix=CHECK-INVALID %s
 // CHECK-C99: error: invalid argument '-std=c99' not allowed with 'OpenCL'


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D21677: Add ignoringImplicit matcher

2016-06-24 Thread Cong Liu via cfe-commits
congliu created this revision.
congliu added a reviewer: klimek.
congliu added a subscriber: cfe-commits.
congliu set the repository for this revision to rL LLVM.
Herald added a subscriber: klimek.

Repository:
  rL LLVM

http://reviews.llvm.org/D21677

Files:
  docs/LibASTMatchersReference.html
  docs/tools/dump_ast_matchers.py
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1088,6 +1088,16 @@
unless(anything());
 }
 
+TEST(IgnoringImplicit, MatchesImplicit) {
+  EXPECT_TRUE(matches("class C {}; C a = C();",
+  varDecl(has(ignoringImplicit(cxxConstructExpr());
+}
+
+TEST(IgnoringImplicit, DoesNotMatchIncorrectly) {
+  EXPECT_TRUE(
+  notMatches("class C {}; C a = C();", varDecl(has(cxxConstructExpr();
+}
+
 TEST(IgnoringImpCasts, MatchesImpCasts) {
   // This test checks that ignoringImpCasts matches when implicit casts are
   // present and its inner matcher alone does not match.
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -265,6 +265,7 @@
   REGISTER_MATCHER(hasUnarySelector);
   REGISTER_MATCHER(hasValueType);
   REGISTER_MATCHER(ifStmt);
+  REGISTER_MATCHER(ignoringImplicit);
   REGISTER_MATCHER(ignoringImpCasts);
   REGISTER_MATCHER(ignoringParenCasts);
   REGISTER_MATCHER(ignoringParenImpCasts);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -548,6 +548,32 @@
  Builder);
 }
 
+/// \brief Matches expressions that match InnerMatcher after any implicit AST
+/// nodes are stripped off.
+///
+/// Parentheses and explicit casts are not discarded.
+/// Given
+/// \code
+///   class C {};
+///   C a = C();
+///   C b;
+///   C c = b;
+/// \endcode
+/// The matchers
+/// \code
+///varDecl(hasInitializer(ignoringImplicit(cxxConstructExpr(
+/// \endcode
+/// would match the declarations for a, b, and c.
+/// While
+/// \code
+///varDecl(hasInitializer(cxxConstructExpr()))
+/// \endcode
+/// only match the declarations for b and c.
+AST_MATCHER_P(Expr, ignoringImplicit, ast_matchers::internal::Matcher,
+  InnerMatcher) {
+  return InnerMatcher.matches(*Node.IgnoreImplicit(), Finder, Builder);
+}
+
 /// \brief Matches expressions that match InnerMatcher after any implicit casts
 /// are stripped off.
 ///
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -2347,7 +2347,7 @@
   private:   int c;
   };
 fieldDecl(isPrivate())
-  matches 'int c;' 
+  matches 'int c;'
 
 
 
@@ -2361,7 +2361,7 @@
   private:   int c;
   };
 fieldDecl(isProtected())
-  matches 'int b;' 
+  matches 'int b;'
 
 
 
@@ -2375,7 +2375,7 @@
   private:   int c;
   };
 fieldDecl(isPublic())
-  matches 'int a;' 
+  matches 'int a;'
 
 
 
@@ -4455,6 +4455,25 @@
 
 
 
+MatcherExpr>ignoringImplicitast_matchers::MatcherExpr> InnerMatcher
+Matches expressions that match InnerMatcher after any implicit AST
+nodes are stripped off.
+
+Parentheses and explicit casts are not discarded.
+Given
+  class C {};
+  C a = C();
+  C b;
+  C c = b;
+The matchers
+   varDecl(hasInitializer(ignoringImplicit(cxxConstructExpr(
+would match the declarations for a, b, and c.
+While
+   varDecl(hasInitializer(cxxConstructExpr()))
+only match the declarations for b and c.
+
+
+
 MatcherExpr>ignoringParenCastsMatcherExpr> InnerMatcher
 Matches expressions that match InnerMatcher after parentheses and
 casts are stripped off.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r273659 - IgnoringImplicit matcher.

2016-06-24 Thread Cong Liu via cfe-commits
Author: congliu
Date: Fri Jun 24 04:38:03 2016
New Revision: 273659

URL: http://llvm.org/viewvc/llvm-project?rev=273659&view=rev
Log:
IgnoringImplicit matcher.

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/docs/tools/dump_ast_matchers.py   (contents, props changed)
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=273659&r1=273658&r2=273659&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Fri Jun 24 04:38:03 2016
@@ -2347,7 +2347,7 @@ Given
   private:   int c;
   };
 fieldDecl(isPrivate())
-  matches 'int c;' 
+  matches 'int c;'
 
 
 
@@ -2361,7 +2361,7 @@ Given
   private:   int c;
   };
 fieldDecl(isProtected())
-  matches 'int b;' 
+  matches 'int b;'
 
 
 
@@ -2375,7 +2375,7 @@ Given
   private:   int c;
   };
 fieldDecl(isPublic())
-  matches 'int a;' 
+  matches 'int a;'
 
 
 
@@ -4455,6 +4455,25 @@ only match the declarations for b, c, an
 
 
 
+MatcherExpr>ignoringImplicitast_matchers::MatcherExpr> 
InnerMatcher
+Matches 
expressions that match InnerMatcher after any implicit AST
+nodes are stripped off.
+
+Parentheses and explicit casts are not discarded.
+Given
+  class C {};
+  C a = C();
+  C b;
+  C c = b;
+The matchers
+   varDecl(hasInitializer(ignoringImplicit(cxxConstructExpr(
+would match the declarations for a, b, and c.
+While
+   varDecl(hasInitializer(cxxConstructExpr()))
+only match the declarations for b and c.
+
+
+
 MatcherExpr>ignoringParenCastsMatcherExpr> 
InnerMatcher
 Matches 
expressions that match InnerMatcher after parentheses and
 casts are stripped off.

Modified: cfe/trunk/docs/tools/dump_ast_matchers.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/tools/dump_ast_matchers.py?rev=273659&r1=273658&r2=273659&view=diff
==
(empty)

Propchange: cfe/trunk/docs/tools/dump_ast_matchers.py
--
svn:executable = *

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=273659&r1=273658&r2=273659&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Jun 24 04:38:03 2016
@@ -548,6 +548,32 @@ AST_POLYMORPHIC_MATCHER_P(
  Builder);
 }
 
+/// \brief Matches expressions that match InnerMatcher after any implicit AST
+/// nodes are stripped off.
+///
+/// Parentheses and explicit casts are not discarded.
+/// Given
+/// \code
+///   class C {};
+///   C a = C();
+///   C b;
+///   C c = b;
+/// \endcode
+/// The matchers
+/// \code
+///varDecl(hasInitializer(ignoringImplicit(cxxConstructExpr(
+/// \endcode
+/// would match the declarations for a, b, and c.
+/// While
+/// \code
+///varDecl(hasInitializer(cxxConstructExpr()))
+/// \endcode
+/// only match the declarations for b and c.
+AST_MATCHER_P(Expr, ignoringImplicit, ast_matchers::internal::Matcher,
+  InnerMatcher) {
+  return InnerMatcher.matches(*Node.IgnoreImplicit(), Finder, Builder);
+}
+
 /// \brief Matches expressions that match InnerMatcher after any implicit casts
 /// are stripped off.
 ///

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=273659&r1=273658&r2=273659&view=diff
==
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Fri Jun 24 04:38:03 2016
@@ -265,6 +265,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(hasUnarySelector);
   REGISTER_MATCHER(hasValueType);
   REGISTER_MATCHER(ifStmt);
+  REGISTER_MATCHER(ignoringImplicit);
   REGISTER_MATCHER(ignoringImpCasts);
   REGISTER_MATCHER(ignoringParenCasts);
   REGISTER_MATCHER(ignoringParenImpCasts);

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp?rev=273659&r1=273658&r2=273659&view=diff
==
-

[clang-tools-extra] r273660 - Remove ignoringImplicit from clang-tidy.

2016-06-24 Thread Cong Liu via cfe-commits
Author: congliu
Date: Fri Jun 24 04:39:28 2016
New Revision: 273660

URL: http://llvm.org/viewvc/llvm-project?rev=273660&view=rev
Log:
Remove ignoringImplicit from clang-tidy.

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/trunk/clang-tidy/utils/Matchers.h

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp?rev=273660&r1=273659&r2=273660&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp Fri Jun 
24 04:39:28 2016
@@ -142,7 +142,7 @@ StatementMatcher makeIteratorLoopMatcher
   StatementMatcher IteratorComparisonMatcher = expr(
   
ignoringParenImpCasts(declRefExpr(to(varDecl().bind(ConditionVarName);
 
-  auto OverloadedNEQMatcher = matchers::ignoringImplicit(
+  auto OverloadedNEQMatcher = ignoringImplicit(
   cxxOperatorCallExpr(hasOverloadedOperatorName("!="), argumentCountIs(2),
   hasArgument(0, IteratorComparisonMatcher),
   hasArgument(1, IteratorBoundMatcher)));

Modified: clang-tools-extra/trunk/clang-tidy/utils/Matchers.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/Matchers.h?rev=273660&r1=273659&r2=273660&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/utils/Matchers.h (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/Matchers.h Fri Jun 24 04:39:28 2016
@@ -17,11 +17,6 @@ namespace clang {
 namespace tidy {
 namespace matchers {
 
-AST_MATCHER_P(Expr, ignoringImplicit,
-  ast_matchers::internal::Matcher, InnerMatcher) {
-  return InnerMatcher.matches(*Node.IgnoreImplicit(), Finder, Builder);
-}
-
 AST_MATCHER(BinaryOperator, isRelationalOperator) {
   return Node.isRelationalOp();
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r273660 - Remove ignoringImplicit from clang-tidy.

2016-06-24 Thread Cong Liu via cfe-commits
It was the previous revision that broke tests,
http://reviews.llvm.org/rL273659. It moved ignoringImplicit to ASTMatcher,
caused some namespace conflict in clang-tidy/misc/DanglingHandleCheck.cpp.
And r273660 solves that, tests are not broken after this revision.

On Fri, Jun 24, 2016 at 12:32 PM Renato Golin 
wrote:

> On 24 June 2016 at 10:39, Cong Liu via cfe-commits
>  wrote:
> > Author: congliu
> > Date: Fri Jun 24 04:39:28 2016
> > New Revision: 273660
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=273660&view=rev
> > Log:
> > Remove ignoringImplicit from clang-tidy.
>
> Hi Cong,
>
> Isn't this leaving untested code in tree? Shouldn't you have reverted
> the patch instead?
>
> cheers,
> --renato
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D15823: Support virtual-near-miss check.

2015-12-30 Thread Cong Liu via cfe-commits
congliu created this revision.
congliu added a reviewer: alexfh.
congliu added a subscriber: cfe-commits.

Virtual function override near miss detection. Function complete. Test 
complete. Do not conduct Fix for now.

http://reviews.llvm.org/D15823

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/VirtualNearMissCheck.cpp
  clang-tidy/misc/VirtualNearMissCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-virtual-near-miss.rst
  test/clang-tidy/misc-virtual-near-miss.cpp

Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -0,0 +1,67 @@
+// RUN: %check_clang_tidy %s misc-virtual-near-miss %t
+
+struct Base{
+  virtual void func();
+  virtual void gunk();
+};
+
+struct Derived:Base{
+  // Should warn
+  // Should not warn "do you want to override 'gunk'?", becuase gunk is already
+  // overriden by this class
+  virtual void funk();
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do you want to override 'func'? [misc-virtual-near-miss]
+
+  // Should warn
+  void func2();
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do you want to override 'func'? [misc-virtual-near-miss]
+
+  void func22(); // Should not warn
+
+  void gunk(); // Should not warn because gunk is override
+
+  // Should warn
+  void fun();
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do you want to override 'func'? [misc-virtual-near-miss]
+};
+
+class Father{
+ public:
+  Father();
+  virtual void func();
+  virtual Father* create(int i);
+};
+
+class Mother{
+ public:
+  Mother();
+  static void method();
+  virtual int method(int argc, const char** argv);
+  virtual int method(int argc) const;
+};
+
+class Child : Father, Mother{
+ public:
+  Child();
+
+  // Should warn
+  virtual void func2();
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do you want to override 'func'? [misc-virtual-near-miss]
+
+  int methoe(int x, char** strs); // Should not warn because param type miss match
+
+  int methoe(int x); // Should not warn because const type miss match
+
+  void methof(int x, const char** strs); // Should not warn because return type miss match
+
+  // Should warn
+  int methoh(int x, const char** strs);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do you want to override 'method'? [misc-virtual-near-miss]
+
+  // Should warn
+  virtual Child* creat(int i);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do you want to override 'create'? [misc-virtual-near-miss]
+
+ private:
+  void funk(); //Should not warn because access miss match
+};
Index: docs/clang-tidy/checks/misc-virtual-near-miss.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-virtual-near-miss.rst
@@ -0,0 +1,4 @@
+misc-virtual-near-miss
+==
+
+FIXME: Describe what patterns does the check detect and why. Give examples.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -56,6 +56,7 @@
misc-unused-alias-decls
misc-unused-parameters
misc-unused-raii
+   misc-virtual-near-miss
modernize-loop-convert
modernize-make-unique
modernize-pass-by-value
Index: clang-tidy/misc/VirtualNearMissCheck.h
===
--- /dev/null
+++ clang-tidy/misc/VirtualNearMissCheck.h
@@ -0,0 +1,75 @@
+//===--- VirtualNearMissCheck.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_VIRTUAL_NEAR_MISS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_VIRTUAL_NEAR_MISS_H
+
+#include "../ClangTidy.h"
+#include 
+#include 
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+/// FIXME: Write a short description.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/misc-virtual-near-miss.html
+class VirtualNearMissCheck : public ClangTidyCheck {
+public:
+  VirtualNearMissCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+  static int editDistance(const std::string &SourceStr, const std::string &TargetStr);
+private:
+  /// Return true if the given method overrides some method.
+  bool isOverrideMethod(const CXXMethodDecl *DerivedMD);
+
+  /// Return true if the given method is possible to be overriden by some other
+  /// method.
+  //It should look up the possible_map or update it.

Re: [PATCH] D15823: Support virtual-near-miss check.

2015-12-31 Thread Cong Liu via cfe-commits
congliu marked 2 inline comments as done.


Comment at: clang-tidy/misc/VirtualNearMissCheck.cpp:79
@@ +78,3 @@
+  if (BaseReturnType->isReferenceType() && 
DerivedReturnType->isReferenceType()){
+BaseReturnType = BaseReturnType.getNonReferenceType();
+DerivedReturnType = DerivedReturnType.getNonReferenceType();

alexfh wrote:
> You can call `.getNonReferenceType()` unconditionally to make the code 
> shorter.
The condition is necessary, for the same reason I explained in the comment for 
line 85. 


Comment at: clang-tidy/misc/VirtualNearMissCheck.cpp:85
@@ +84,3 @@
+  }else {
+return false;
+  }

alexfh wrote:
> What if both return types are not references and are not pointers? Why do you 
> return `false` in this case?
This is to deal with an special case of C++ override. Usually the return type 
of the override and overriden should be the same. The exception is that the 
return type ban be a reference (or pointer) to the class themselves. For 
example, 
  class Base{
virtual Base* func();
  };
  class Derived : Base{
virtual Derived* func();
  };
In this case, the Derived::func() does override Base::func(), even though the 
return type are not the same.
So if the return types are not the same (line 72 assured that), and are not 
both references (or pointers), we can rule out the possibility of override, and 
therefore return false.


http://reviews.llvm.org/D15823



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15823: Support virtual-near-miss check.

2016-01-04 Thread Cong Liu via cfe-commits
congliu marked 20 inline comments as done.


Comment at: clang-tidy/misc/VirtualNearMissCheck.cpp:59
@@ +58,3 @@
+bool VirtualNearMissCheck::isOverrideMethod(const CXXMethodDecl *MD){
+  return MD->size_overridden_methods() > 0 || MD->hasAttr();
+}

alexfh wrote:
> Why is the `hasAttr()` part needed? Do you have an example of 
> code that results in `size_overridden_methods() == 0` and 
> `hasAttr() == true`?
I tried some cases, but haven't found an example for that case. 
I saw the same code in [[ 
https://cs.corp.google.com/#piper///depot/google3/third_party/llvm/llvm/tools/clang/include/clang/ASTMatchers/ASTMatchers.h&l=3500
 | AST_MATCHER(CXXMethodDecl, isOverride) ]]. 
I'm not sure why there is a "hasAttr". 


http://reviews.llvm.org/D15823



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15823: Support virtual-near-miss check.

2016-01-07 Thread Cong Liu via cfe-commits
congliu updated this revision to Diff 44197.
congliu added a comment.

- Corrected naming styles; Used clang-format; Add doc to .h
- Removed useless parentheses, braces around one-line ifs.
- Added doc; Corrected style and typos for test.
- Implemented c++ [class.virtual]p7. But has bug.
- Support ambiguity checking.
- Completed virtual covarient check. Updated test.


http://reviews.llvm.org/D15823

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/VirtualNearMissCheck.cpp
  clang-tidy/misc/VirtualNearMissCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-virtual-near-miss.rst
  test/clang-tidy/misc-virtual-near-miss.cpp

Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -0,0 +1,65 @@
+// RUN: %check_clang_tidy %s misc-virtual-near-miss %t
+
+struct Base {
+  virtual void func();
+  virtual void gunk();
+};
+
+struct Derived : Base {
+  // Should not warn "do you want to override 'gunk'?", becuase gunk is already
+  // overriden by this class.
+  virtual void funk();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do you want to override 'func'? [misc-virtual-near-miss]
+
+  void func2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do you want to override 'func'?
+
+  void func22(); // Should not warn.
+
+  void gunk(); // Should not warn, because gunk is override.
+
+  void fun();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do you want to override 'func'?
+};
+
+class Father {
+public:
+  Father();
+  virtual void func();
+  virtual Father *create(int i);
+  virtual Base &&generate();
+};
+
+class Mother {
+public:
+  Mother();
+  static void method();
+  virtual int method(int argc, const char **argv);
+  virtual int method(int argc) const;
+};
+
+class Child : Father, Mother {
+public:
+  Child();
+
+  virtual void func2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do you want to override 'func'?
+
+  int methoe(int x, char **strs); // Should not warn, because param type missmatch.
+
+  int methoe(int x); // Should not warn, because const type missmatch.
+
+  void methof(int x, const char **strs); // Should not warn, because return type missmatch.
+
+  int methoh(int x, const char **strs);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do you want to override 'method'?
+
+  virtual Child *creat(int i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do you want to override 'create'?
+
+  virtual Derived &&generat();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do you want to override 'generate'?
+
+private:
+  void funk(); //Should not warn, because access missmatch.
+};
Index: docs/clang-tidy/checks/misc-virtual-near-miss.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-virtual-near-miss.rst
@@ -0,0 +1,17 @@
+misc-virtual-near-miss
+==
+
+Warn if a function is a near miss (ie. short edit distance) to a virtual function from a base class.
+
+Example:
+
+.. code-block:: c++
+
+  struct Base {
+virtual void func();
+  };
+
+  struct Derived : Base {
+virtual funk();
+// warning: Do you want to override 'func'?
+  };
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -56,6 +56,7 @@
misc-unused-alias-decls
misc-unused-parameters
misc-unused-raii
+   misc-virtual-near-miss
modernize-loop-convert
modernize-make-unique
modernize-pass-by-value
Index: clang-tidy/misc/VirtualNearMissCheck.h
===
--- /dev/null
+++ clang-tidy/misc/VirtualNearMissCheck.h
@@ -0,0 +1,94 @@
+//===--- VirtualNearMissCheck.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_VIRTUAL_NEAR_MISS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_VIRTUAL_NEAR_MISS_H
+
+#include "../ClangTidy.h"
+#include 
+#include 
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+/// Generate warning if an method in derived class is a near miss to some virtual
+/// to base class:
+/// \code
+///   struct Base{
+/// virtual void func();
+///   };
+///   struct Derived:Base{
+/// virtual void funk(); // warning: do you want to override 'func'?
+///   };
+/// \endcode
+class VirtualNearMissCheck : public ClangTidyCheck {
+public:
+  VirtualNearMissCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void c

Re: [PATCH] D15823: Support virtual-near-miss check.

2016-01-08 Thread Cong Liu via cfe-commits
congliu updated this revision to Diff 44328.
congliu marked 33 inline comments as done.
congliu added a comment.

- Completed [class.virtual] p7 covarient check. Updated test.
- Corrected implement of checkParamType.
- Clean up.
- Corrected typos. Changed some methods to free-standing. Changed warning 
message. Updated tests.
- Finished correcting cpp. Updated doc.


http://reviews.llvm.org/D15823

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/VirtualNearMissCheck.cpp
  clang-tidy/misc/VirtualNearMissCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-virtual-near-miss.rst
  test/clang-tidy/misc-virtual-near-miss.cpp

Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -0,0 +1,65 @@
+// RUN: %check_clang_tidy %s misc-virtual-near-miss %t
+
+struct Base {
+  virtual void func();
+  virtual void gunk();
+};
+
+struct Derived : Base {
+  // Should not warn "do you want to override 'gunk'?", because gunk is already
+  // overriden by this class.
+  virtual void funk();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'Derived::funk' has a similar name and the same signature with virtual method 'Base::func'. Did you meant to override it? [misc-virtual-near-miss]
+
+  void func2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'Derived::func2' has a similar name and the same signature with virtual method 'Base::func'. Did you meant to override it?
+
+  void func22(); // Should not warn.
+
+  void gunk(); // Should not warn: gunk is override.
+
+  void fun();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'Derived::fun' has a similar name and the same signature with virtual method 'Base::func'. Did you meant to override it?
+};
+
+class Father {
+public:
+  Father();
+  virtual void func();
+  virtual Father *create(int i);
+  virtual Base &&generate();
+};
+
+class Mother {
+public:
+  Mother();
+  static void method();
+  virtual int method(int argc, const char **argv);
+  virtual int method(int argc) const;
+};
+
+class Child : Father, Mother {
+public:
+  Child();
+
+  virtual void func2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'Child::func2' has a similar name and the same signature with virtual method 'Father::func'. Did you meant to override it?
+
+  int methoe(int x, char **strs); // Should not warn: parameter types don't match.
+
+  int methoe(int x); // Should not warn: method is not const.
+
+  void methof(int x, const char **strs); // Should not warn: return types don't match.
+
+  int methoh(int x, const char **strs);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'Child::methoh' has a similar name and the same signature with virtual method 'Mother::method'. Did you meant to override it?
+
+  virtual Child *creat(int i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'Child::creat' has a similar name and the same signature with virtual method 'Father::create'. Did you meant to override it?
+
+  virtual Derived &&generat();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'Child::generat' has a similar name and the same signature with virtual method 'Father::generate'. Did you meant to override it?
+
+private:
+  void funk(); // Should not warn: access qualifers don't match.
+};
Index: docs/clang-tidy/checks/misc-virtual-near-miss.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-virtual-near-miss.rst
@@ -0,0 +1,17 @@
+misc-virtual-near-miss
+==
+
+Warn if a function is a near miss (ie. the name is very similar and the function signiture is the same) to a virtual function from a base class.
+
+Example:
+
+.. code-block:: c++
+
+  struct Base {
+virtual void func();
+  };
+
+  struct Derived : Base {
+virtual funk();
+// warning: Do you want to override 'func'?
+  };
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -56,6 +56,7 @@
misc-unused-alias-decls
misc-unused-parameters
misc-unused-raii
+   misc-virtual-near-miss
modernize-loop-convert
modernize-make-unique
modernize-pass-by-value
Index: clang-tidy/misc/VirtualNearMissCheck.h
===
--- /dev/null
+++ clang-tidy/misc/VirtualNearMissCheck.h
@@ -0,0 +1,65 @@
+//===--- VirtualNearMissCheck.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_VIRTUAL_NEAR_MISS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_VIRTUAL_NEAR_MISS_H

Re: [PATCH] D15823: Support virtual-near-miss check.

2016-01-08 Thread Cong Liu via cfe-commits
congliu added inline comments.


Comment at: clang-tidy/misc/VirtualNearMissCheck.cpp:232
@@ +231,3 @@
+const auto *BaseRD = BaseSpec.getType()->getAsCXXRecordDecl();
+if (BaseRD == nullptr)
+  return;

alexfh wrote:
> 1. When is this going to be nullptr?
> 2. Why do you return here instead of continuing to check other base classes?
1. Just to assure it's not nullptr. If the base specification contains a class 
type that was not declared anywhere, it would be nullptr. I found similar code 
here [[ 
https://cs.corp.google.com/#piper///depot/google3/third_party/llvm/llvm/tools/clang/tools/extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp&l=121
 | NewDeleteOverloadsCheck.cpp, line 121]]
2. Sorry, it's a mistake, should be 'continue' not 'return'.


Comment at: test/clang-tidy/misc-virtual-near-miss.cpp:41
@@ +40,3 @@
+
+class Child : Father, Mother {
+public:

alexfh wrote:
> Is private inheritance intended here?
Yes, it's intended. This is for the case in line 57: although Father is a 
private base class of Child, since that function itself is in Child class, the 
conversion is accessible. 


http://reviews.llvm.org/D15823



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15823: Support virtual-near-miss check.

2016-01-12 Thread Cong Liu via cfe-commits
congliu marked 9 inline comments as done.
congliu added a comment.

Fixed. For next steps, I will go through the results of clangmr, find out false 
alarms, and fix them.



Comment at: clang-tidy/misc/VirtualNearMissCheck.cpp:90
@@ +89,3 @@
+// Check ambiguity.
+if (Paths.isAmbiguous(Context->getCanonicalType(BTy).getUnqualifiedType()))
+  return false;

alexfh wrote:
> I wonder whether `BTy.getCanonicalType().getUnqualifiedType()` will work here.
I'm afraid they're different. [[ 
http://clang.llvm.org/doxygen/classclang_1_1CXXBasePaths.html#a61341e71c248072b3f5bfbd54aea6174
 | CXXBasePaths.isAmbiguous ]] receives a CanQualType parameter, while  
BTy.getCanonicalType().getUnqualifiedType() returns a QualType object. 


http://reviews.llvm.org/D15823



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15823: Support virtual-near-miss check.

2016-01-12 Thread Cong Liu via cfe-commits
congliu updated this revision to Diff 44661.
congliu added a comment.

- Removed braces; corrected comments; updated test.


http://reviews.llvm.org/D15823

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/VirtualNearMissCheck.cpp
  clang-tidy/misc/VirtualNearMissCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-virtual-near-miss.rst
  test/clang-tidy/misc-virtual-near-miss.cpp

Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -0,0 +1,65 @@
+// RUN: %check_clang_tidy %s misc-virtual-near-miss %t
+
+struct Base {
+  virtual void func();
+  virtual void gunk();
+};
+
+struct Derived : Base {
+  // Should not warn "do you want to override 'gunk'?", because gunk is already
+  // overriden by this class.
+  virtual void funk();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::funk' has a similar name and the same signature as virtual method 'Base::func'; did you mean to override it? [misc-virtual-near-miss]
+
+  void func2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::func2' has {{.*}} 'Base::func'
+
+  void func22(); // Should not warn.
+
+  void gunk(); // Should not warn: gunk is override.
+
+  void fun();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::fun' has {{.*}} 'Base::func'
+};
+
+class Father {
+public:
+  Father();
+  virtual void func();
+  virtual Father *create(int i);
+  virtual Base &&generate();
+};
+
+class Mother {
+public:
+  Mother();
+  static void method();
+  virtual int method(int argc, const char **argv);
+  virtual int method(int argc) const;
+};
+
+class Child : private Father, private Mother {
+public:
+  Child();
+
+  virtual void func2();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::func2' has {{.*}} 'Father::func'
+
+  int methoe(int x, char **strs); // Should not warn: parameter types don't match.
+
+  int methoe(int x); // Should not warn: method is not const.
+
+  void methof(int x, const char **strs); // Should not warn: return types don't match.
+
+  int methoh(int x, const char **strs);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::methoh' has {{.*}} 'Mother::method'
+
+  virtual Child *creat(int i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::creat' has {{.*}} 'Father::create'
+
+  virtual Derived &&generat();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::generat' has {{.*}} 'Father::generate'
+
+private:
+  void funk(); // Should not warn: access qualifers don't match.
+};
Index: docs/clang-tidy/checks/misc-virtual-near-miss.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-virtual-near-miss.rst
@@ -0,0 +1,17 @@
+misc-virtual-near-miss
+==
+
+Warn if a function is a near miss (ie. the name is very similar and the function signiture is the same) to a virtual function from a base class.
+
+Example:
+
+.. code-block:: c++
+
+  struct Base {
+virtual void func();
+  };
+
+  struct Derived : Base {
+virtual funk();
+// warning: Do you want to override 'func'?
+  };
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -56,6 +56,7 @@
misc-unused-alias-decls
misc-unused-parameters
misc-unused-raii
+   misc-virtual-near-miss
modernize-loop-convert
modernize-make-unique
modernize-pass-by-value
Index: clang-tidy/misc/VirtualNearMissCheck.h
===
--- /dev/null
+++ clang-tidy/misc/VirtualNearMissCheck.h
@@ -0,0 +1,65 @@
+//===--- VirtualNearMissCheck.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_VIRTUAL_NEAR_MISS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_VIRTUAL_NEAR_MISS_H
+
+#include "../ClangTidy.h"
+#include 
+#include 
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+/// \brief Checks for near miss of virtual methods.
+///
+/// For a method in a derived class, this check looks for virtual method with a
+/// very similar name and an identical signature defined in a base class.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/misc-virtual-near-miss.html
+class VirtualNearMissCheck : public ClangTidyCheck {
+public:
+  VirtualNearMissCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder 

Re: [PATCH] D16179: [clang-tidy] Handle decayed types and other improvements in VirtualNearMiss check.

2016-01-15 Thread Cong Liu via cfe-commits
congliu added a comment.

> - Ignore qualifiers.


I don't think we should ignore qualifiers. Please see my inline comment for 
line 52 of the test file.



Comment at: clang-tidy/misc/VirtualNearMissCheck.cpp:240
@@ -247,2 +239,3 @@
 unsigned EditDistance =
-BaseMD->getName().edit_distance(DerivedMD->getName());
+StringRef(BaseMD->getNameAsString())
+.edit_distance(DerivedMD->getNameAsString());

NamedDecl::getName() directly returns a StringRef. Why using 
"getNameAsString()"? 


Comment at: test/clang-tidy/misc-virtual-near-miss.cpp:52
@@ -49,2 +51,3 @@
 
-  int methoe(int x); // Should not warn: method is not const.
+  int methoe(int x);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::methoe' has 
{{.*}} 'Mother::method'

If a function in derived class has a same name but different cv-qualifiers as a 
function in base class, they are not regarded as overriding. For example, 

```
class Mother{ 
  virtual int method(int argc) const;
};
class Child : Mother{
  int method(int x);
};
```
In this case, Child::method does not overrides Mother::method, but hides it. So 
I think we should not warn for "methoe", because even if the programmer changes 
"methoe" to "method", it's not an overriding. 


http://reviews.llvm.org/D16179



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16536: Fix crashing on user-defined conversion.

2016-01-25 Thread Cong Liu via cfe-commits
congliu created this revision.
congliu added a reviewer: alexfh.
congliu added a subscriber: cfe-commits.

Fix the assertion failure for the user-defined conversion method. e.g.: 
operator bool()

http://reviews.llvm.org/D16536

Files:
  clang-tidy/misc/VirtualNearMissCheck.cpp
  test/clang-tidy/misc-virtual-near-miss.cpp

Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- test/clang-tidy/misc-virtual-near-miss.cpp
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -69,6 +69,7 @@
   int decaz(const char str[]);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::decaz' has {{.*}} 
'Mother::decay'
 
+  operator bool();
 private:
   void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::funk' has {{.*}} 
'Father::func'
Index: clang-tidy/misc/VirtualNearMissCheck.cpp
===
--- clang-tidy/misc/VirtualNearMissCheck.cpp
+++ clang-tidy/misc/VirtualNearMissCheck.cpp
@@ -169,6 +169,14 @@
   return MD->getQualifiedNameAsString() + " " + MD->getType().getAsString();
 }
 
+/// Finds out if the given method is a user-defined conversion.
+/// A user-defined conversion is of the following form:
+///   operator TypeName()
+static bool isUserDefinedConversion(const CXXMethodDecl *MD) {
+  return StringRef(MD->getNameAsString()).find(StringRef("operator ")) !=
+ StringRef::npos;
+}
+
 bool VirtualNearMissCheck::isPossibleToBeOverridden(
 const CXXMethodDecl *BaseMD) {
   std::string Id = generateMethodId(BaseMD);
@@ -178,7 +186,8 @@
 
   bool IsPossible = !BaseMD->isImplicit() && !isa(BaseMD) 
&&
 !isa(BaseMD) && BaseMD->isVirtual() &&
-!BaseMD->isOverloadedOperator();
+!BaseMD->isOverloadedOperator() &&
+!isUserDefinedConversion(BaseMD);
   PossibleMap[Id] = IsPossible;
   return IsPossible;
 }
@@ -226,6 +235,9 @@
   if (DerivedMD->isOverloadedOperator())
 return;
 
+  if (isUserDefinedConversion(DerivedMD))
+return;
+
   const ASTContext *Context = Result.Context;
 
   const auto *DerivedRD = DerivedMD->getParent();


Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- test/clang-tidy/misc-virtual-near-miss.cpp
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -69,6 +69,7 @@
   int decaz(const char str[]);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::decaz' has {{.*}} 'Mother::decay'
 
+  operator bool();
 private:
   void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::funk' has {{.*}} 'Father::func'
Index: clang-tidy/misc/VirtualNearMissCheck.cpp
===
--- clang-tidy/misc/VirtualNearMissCheck.cpp
+++ clang-tidy/misc/VirtualNearMissCheck.cpp
@@ -169,6 +169,14 @@
   return MD->getQualifiedNameAsString() + " " + MD->getType().getAsString();
 }
 
+/// Finds out if the given method is a user-defined conversion.
+/// A user-defined conversion is of the following form:
+///   operator TypeName()
+static bool isUserDefinedConversion(const CXXMethodDecl *MD) {
+  return StringRef(MD->getNameAsString()).find(StringRef("operator ")) !=
+ StringRef::npos;
+}
+
 bool VirtualNearMissCheck::isPossibleToBeOverridden(
 const CXXMethodDecl *BaseMD) {
   std::string Id = generateMethodId(BaseMD);
@@ -178,7 +186,8 @@
 
   bool IsPossible = !BaseMD->isImplicit() && !isa(BaseMD) &&
 !isa(BaseMD) && BaseMD->isVirtual() &&
-!BaseMD->isOverloadedOperator();
+!BaseMD->isOverloadedOperator() &&
+!isUserDefinedConversion(BaseMD);
   PossibleMap[Id] = IsPossible;
   return IsPossible;
 }
@@ -226,6 +235,9 @@
   if (DerivedMD->isOverloadedOperator())
 return;
 
+  if (isUserDefinedConversion(DerivedMD))
+return;
+
   const ASTContext *Context = Result.Context;
 
   const auto *DerivedRD = DerivedMD->getParent();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D16536: Fix crashing on user-defined conversion.

2016-01-25 Thread Cong Liu via cfe-commits
congliu updated this revision to Diff 45873.
congliu added a comment.

- Address the comment and clean up the code.


http://reviews.llvm.org/D16536

Files:
  clang-tidy/misc/VirtualNearMissCheck.cpp
  test/clang-tidy/misc-virtual-near-miss.cpp

Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- test/clang-tidy/misc-virtual-near-miss.cpp
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -69,6 +69,7 @@
   int decaz(const char str[]);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::decaz' has {{.*}} 
'Mother::decay'
 
+  operator bool();
 private:
   void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::funk' has {{.*}} 
'Father::func'
Index: clang-tidy/misc/VirtualNearMissCheck.cpp
===
--- clang-tidy/misc/VirtualNearMissCheck.cpp
+++ clang-tidy/misc/VirtualNearMissCheck.cpp
@@ -178,7 +178,8 @@
 
   bool IsPossible = !BaseMD->isImplicit() && !isa(BaseMD) 
&&
 !isa(BaseMD) && BaseMD->isVirtual() &&
-!BaseMD->isOverloadedOperator();
+!BaseMD->isOverloadedOperator() &&
+!isa(BaseMD);
   PossibleMap[Id] = IsPossible;
   return IsPossible;
 }
@@ -210,8 +211,9 @@
 return;
 
   Finder->addMatcher(
-  cxxMethodDecl(unless(anyOf(isOverride(), isImplicit(),
- cxxConstructorDecl(), cxxDestructorDecl(
+  cxxMethodDecl(
+  unless(anyOf(isOverride(), isImplicit(), cxxConstructorDecl(),
+   cxxDestructorDecl(), cxxConversionDecl(
   .bind("method"),
   this);
 }


Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- test/clang-tidy/misc-virtual-near-miss.cpp
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -69,6 +69,7 @@
   int decaz(const char str[]);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::decaz' has {{.*}} 'Mother::decay'
 
+  operator bool();
 private:
   void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::funk' has {{.*}} 'Father::func'
Index: clang-tidy/misc/VirtualNearMissCheck.cpp
===
--- clang-tidy/misc/VirtualNearMissCheck.cpp
+++ clang-tidy/misc/VirtualNearMissCheck.cpp
@@ -178,7 +178,8 @@
 
   bool IsPossible = !BaseMD->isImplicit() && !isa(BaseMD) &&
 !isa(BaseMD) && BaseMD->isVirtual() &&
-!BaseMD->isOverloadedOperator();
+!BaseMD->isOverloadedOperator() &&
+!isa(BaseMD);
   PossibleMap[Id] = IsPossible;
   return IsPossible;
 }
@@ -210,8 +211,9 @@
 return;
 
   Finder->addMatcher(
-  cxxMethodDecl(unless(anyOf(isOverride(), isImplicit(),
- cxxConstructorDecl(), cxxDestructorDecl(
+  cxxMethodDecl(
+  unless(anyOf(isOverride(), isImplicit(), cxxConstructorDecl(),
+   cxxDestructorDecl(), cxxConversionDecl(
   .bind("method"),
   this);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D16536: Fix crashing on user-defined conversion.

2016-01-25 Thread Cong Liu via cfe-commits
congliu added inline comments.


Comment at: clang-tidy/misc/VirtualNearMissCheck.cpp:175
@@ +174,3 @@
+///   operator TypeName()
+static bool isUserDefinedConversion(const CXXMethodDecl *MD) {
+  return StringRef(MD->getNameAsString()).find(StringRef("operator ")) !=

aaron.ballman wrote:
> Why not `isa(MD)` instead?
Thanks!


http://reviews.llvm.org/D16536



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16587: Fixed function params comparison. Updated docs and tests.

2016-01-26 Thread Cong Liu via cfe-commits
congliu created this revision.
congliu added a reviewer: alexfh.
congliu added a subscriber: cfe-commits.

"checkParamTypes" may fail if the the type of some parameter is not canonical. 
Fixed it by comparing canonical types. And added "getCanonicalType()" and 
"getCanonicalDecl()" on more places to prevent potential fail.

http://reviews.llvm.org/D16587

Files:
  clang-tidy/misc/VirtualNearMissCheck.cpp
  docs/clang-tidy/checks/misc-virtual-near-miss.rst
  test/clang-tidy/misc-virtual-near-miss.cpp

Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- test/clang-tidy/misc-virtual-near-miss.cpp
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -26,12 +26,15 @@
   Derived &operator==(const Base &); // Should not warn: operators are ignored.
 };
 
+typedef Derived derived_type;
+
 class Father {
 public:
   Father();
   virtual void func();
   virtual Father *create(int i);
   virtual Base &&generate();
+  virtual Base *canonical(Derived D);
 };
 
 class Mother {
@@ -70,6 +73,11 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::decaz' has {{.*}} 'Mother::decay'
 
   operator bool();
+
+  derived_type *canonica(derived_type D);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::canonica' has {{.*}} 'Father::canonical'
+
+
 private:
   void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::funk' has {{.*}} 'Father::func'
Index: docs/clang-tidy/checks/misc-virtual-near-miss.rst
===
--- docs/clang-tidy/checks/misc-virtual-near-miss.rst
+++ docs/clang-tidy/checks/misc-virtual-near-miss.rst
@@ -13,5 +13,5 @@
 
   struct Derived : Base {
 virtual funk();
-// warning: Do you want to override 'func'?
+// warning: 'Derived::funk' has a similar name and the same signature as virtual method 'Base::func'; did you mean to override it?
   };
Index: clang-tidy/misc/VirtualNearMissCheck.cpp
===
--- clang-tidy/misc/VirtualNearMissCheck.cpp
+++ clang-tidy/misc/VirtualNearMissCheck.cpp
@@ -32,10 +32,14 @@
 static bool checkOverridingFunctionReturnType(const ASTContext *Context,
   const CXXMethodDecl *BaseMD,
   const CXXMethodDecl *DerivedMD) {
-  QualType BaseReturnTy =
-  BaseMD->getType()->getAs()->getReturnType();
-  QualType DerivedReturnTy =
-  DerivedMD->getType()->getAs()->getReturnType();
+  QualType BaseReturnTy = BaseMD->getType()
+  ->getAs()
+  ->getReturnType()
+  .getCanonicalType();
+  QualType DerivedReturnTy = DerivedMD->getType()
+ ->getAs()
+ ->getReturnType()
+ .getCanonicalType();
 
   if (DerivedReturnTy->isDependentType() || BaseReturnTy->isDependentType())
 return false;
@@ -54,8 +58,8 @@
   /// BTy is the class type in return type of BaseMD. For example,
   ///B* Base::md()
   /// While BRD is the declaration of B.
-  QualType DTy = DerivedReturnTy->getPointeeType();
-  QualType BTy = BaseReturnTy->getPointeeType();
+  QualType DTy = DerivedReturnTy->getPointeeType().getCanonicalType();
+  QualType BTy = BaseReturnTy->getPointeeType().getCanonicalType();
 
   const CXXRecordDecl *DRD = DTy->getAsCXXRecordDecl();
   const CXXRecordDecl *BRD = BTy->getAsCXXRecordDecl();
@@ -81,7 +85,7 @@
 // Check accessibility.
 // FIXME: We currently only support checking if B is accessible base class
 // of D, or D is the same class which DerivedMD is in.
-bool IsItself = DRD == DerivedMD->getParent();
+bool IsItself = DRD == DerivedMD->getParent()->getCanonicalDecl();
 bool HasPublicAccess = false;
 for (const auto &Path : Paths) {
   if (Path.Access == AS_public)
@@ -121,8 +125,9 @@
 return false;
 
   for (unsigned I = 0; I < NumParamA; I++) {
-if (getDecayedType(BaseMD->getParamDecl(I)->getType()) !=
-getDecayedType(DerivedMD->getParamDecl(I)->getType()))
+if (getDecayedType(BaseMD->getParamDecl(I)->getType().getCanonicalType()) !=
+getDecayedType(
+DerivedMD->getParamDecl(I)->getType().getCanonicalType()))
   return false;
   }
   return true;
@@ -230,7 +235,7 @@
 
   const ASTContext *Context = Result.Context;
 
-  const auto *DerivedRD = DerivedMD->getParent();
+  const auto *DerivedRD = DerivedMD->getParent()->getCanonicalDecl();
 
   for (const auto &BaseSpec : DerivedRD->bases()) {
 if (const auto *BaseRD = BaseSpec.getType()->getAsCXXRecordDecl()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D16587: Fixed function params comparison. Updated docs and tests.

2016-01-28 Thread Cong Liu via cfe-commits
congliu updated this revision to Diff 46359.
congliu added a comment.

- Fixed bugs introduced by getCanonicalDecl. Has errs log.
- Cleared up logs.
- Added mathcers for static method and overloaded operator.
- Change key type of map from string to pointer to imporve performance.
- Change implementation of checkOverrideByDerivedMethod.


http://reviews.llvm.org/D16587

Files:
  clang-tidy/misc/VirtualNearMissCheck.cpp
  clang-tidy/misc/VirtualNearMissCheck.h
  docs/clang-tidy/checks/misc-virtual-near-miss.rst
  test/clang-tidy/misc-virtual-near-miss.cpp

Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- test/clang-tidy/misc-virtual-near-miss.cpp
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -26,12 +26,15 @@
   Derived &operator==(const Base &); // Should not warn: operators are ignored.
 };
 
+typedef Derived derived_type;
+
 class Father {
 public:
   Father();
   virtual void func();
   virtual Father *create(int i);
   virtual Base &&generate();
+  virtual Base *canonical(Derived D);
 };
 
 class Mother {
@@ -70,6 +73,11 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::decaz' has {{.*}} 'Mother::decay'
 
   operator bool();
+
+  derived_type *canonica(derived_type D);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::canonica' has {{.*}} 'Father::canonical'
+
+
 private:
   void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::funk' has {{.*}} 'Father::func'
Index: docs/clang-tidy/checks/misc-virtual-near-miss.rst
===
--- docs/clang-tidy/checks/misc-virtual-near-miss.rst
+++ docs/clang-tidy/checks/misc-virtual-near-miss.rst
@@ -13,5 +13,5 @@
 
   struct Derived : Base {
 virtual funk();
-// warning: Do you want to override 'func'?
+// warning: 'Derived::funk' has a similar name and the same signature as virtual method 'Base::func'; did you mean to override it?
   };
Index: clang-tidy/misc/VirtualNearMissCheck.h
===
--- clang-tidy/misc/VirtualNearMissCheck.h
+++ clang-tidy/misc/VirtualNearMissCheck.h
@@ -48,12 +48,13 @@
 
   /// key: the unique ID of a method;
   /// value: whether the method is possible to be overridden.
-  std::map PossibleMap;
+  std::map PossibleMap;
 
   /// key: 
   /// value: whether the base method is overridden by some method in the derived
   /// class.
-  std::map, bool> OverriddenMap;
+  std::map, bool>
+  OverriddenMap;
 
   const unsigned EditDistanceThreshold = 1;
 };
Index: clang-tidy/misc/VirtualNearMissCheck.cpp
===
--- clang-tidy/misc/VirtualNearMissCheck.cpp
+++ clang-tidy/misc/VirtualNearMissCheck.cpp
@@ -19,6 +19,12 @@
 namespace tidy {
 namespace misc {
 
+AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
+
+AST_MATCHER(CXXMethodDecl, isOverloadedOperator) {
+  return Node.isOverloadedOperator();
+}
+
 /// Finds out if the given method overrides some method.
 static bool isOverrideMethod(const CXXMethodDecl *MD) {
   return MD->size_overridden_methods() > 0 || MD->hasAttr();
@@ -32,10 +38,14 @@
 static bool checkOverridingFunctionReturnType(const ASTContext *Context,
   const CXXMethodDecl *BaseMD,
   const CXXMethodDecl *DerivedMD) {
-  QualType BaseReturnTy =
-  BaseMD->getType()->getAs()->getReturnType();
-  QualType DerivedReturnTy =
-  DerivedMD->getType()->getAs()->getReturnType();
+  QualType BaseReturnTy = BaseMD->getType()
+  ->getAs()
+  ->getReturnType()
+  .getCanonicalType();
+  QualType DerivedReturnTy = DerivedMD->getType()
+ ->getAs()
+ ->getReturnType()
+ .getCanonicalType();
 
   if (DerivedReturnTy->isDependentType() || BaseReturnTy->isDependentType())
 return false;
@@ -54,8 +64,8 @@
   /// BTy is the class type in return type of BaseMD. For example,
   ///B* Base::md()
   /// While BRD is the declaration of B.
-  QualType DTy = DerivedReturnTy->getPointeeType();
-  QualType BTy = BaseReturnTy->getPointeeType();
+  QualType DTy = DerivedReturnTy->getPointeeType().getCanonicalType();
+  QualType BTy = BaseReturnTy->getPointeeType().getCanonicalType();
 
   const CXXRecordDecl *DRD = DTy->getAsCXXRecordDecl();
   const CXXRecordDecl *BRD = BTy->getAsCXXRecordDecl();
@@ -81,7 +91,8 @@
 // Check accessibility.
 // FIXME: We currently only support checking if B is accessible base class
 // of D, or D is the same class which DerivedMD is in.
-bool IsItself = DRD == DerivedMD->getParent();
+bool IsItself =
+DRD->getCanonicalDecl() == DerivedMD->getParent()->getCanonicalDecl();
 bool HasPublicAccess = 

Re: [PATCH] D16587: Fixed function params comparison. Updated docs and tests.

2016-01-28 Thread Cong Liu via cfe-commits
congliu updated this revision to Diff 46360.
congliu added a comment.

- Fixed a nit in test file.


http://reviews.llvm.org/D16587

Files:
  clang-tidy/misc/VirtualNearMissCheck.cpp
  clang-tidy/misc/VirtualNearMissCheck.h
  docs/clang-tidy/checks/misc-virtual-near-miss.rst
  test/clang-tidy/misc-virtual-near-miss.cpp

Index: test/clang-tidy/misc-virtual-near-miss.cpp
===
--- test/clang-tidy/misc-virtual-near-miss.cpp
+++ test/clang-tidy/misc-virtual-near-miss.cpp
@@ -26,12 +26,15 @@
   Derived &operator==(const Base &); // Should not warn: operators are ignored.
 };
 
+typedef Derived derived_type;
+
 class Father {
 public:
   Father();
   virtual void func();
   virtual Father *create(int i);
   virtual Base &&generate();
+  virtual Base *canonical(Derived D);
 };
 
 class Mother {
@@ -70,6 +73,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::decaz' has {{.*}} 'Mother::decay'
 
   operator bool();
+
+  derived_type *canonica(derived_type D);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::canonica' has {{.*}} 'Father::canonical'
+
 private:
   void funk();
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::funk' has {{.*}} 'Father::func'
Index: docs/clang-tidy/checks/misc-virtual-near-miss.rst
===
--- docs/clang-tidy/checks/misc-virtual-near-miss.rst
+++ docs/clang-tidy/checks/misc-virtual-near-miss.rst
@@ -13,5 +13,5 @@
 
   struct Derived : Base {
 virtual funk();
-// warning: Do you want to override 'func'?
+// warning: 'Derived::funk' has a similar name and the same signature as virtual method 'Base::func'; did you mean to override it?
   };
Index: clang-tidy/misc/VirtualNearMissCheck.h
===
--- clang-tidy/misc/VirtualNearMissCheck.h
+++ clang-tidy/misc/VirtualNearMissCheck.h
@@ -48,12 +48,13 @@
 
   /// key: the unique ID of a method;
   /// value: whether the method is possible to be overridden.
-  std::map PossibleMap;
+  std::map PossibleMap;
 
   /// key: 
   /// value: whether the base method is overridden by some method in the derived
   /// class.
-  std::map, bool> OverriddenMap;
+  std::map, bool>
+  OverriddenMap;
 
   const unsigned EditDistanceThreshold = 1;
 };
Index: clang-tidy/misc/VirtualNearMissCheck.cpp
===
--- clang-tidy/misc/VirtualNearMissCheck.cpp
+++ clang-tidy/misc/VirtualNearMissCheck.cpp
@@ -19,6 +19,12 @@
 namespace tidy {
 namespace misc {
 
+AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
+
+AST_MATCHER(CXXMethodDecl, isOverloadedOperator) {
+  return Node.isOverloadedOperator();
+}
+
 /// Finds out if the given method overrides some method.
 static bool isOverrideMethod(const CXXMethodDecl *MD) {
   return MD->size_overridden_methods() > 0 || MD->hasAttr();
@@ -32,10 +38,14 @@
 static bool checkOverridingFunctionReturnType(const ASTContext *Context,
   const CXXMethodDecl *BaseMD,
   const CXXMethodDecl *DerivedMD) {
-  QualType BaseReturnTy =
-  BaseMD->getType()->getAs()->getReturnType();
-  QualType DerivedReturnTy =
-  DerivedMD->getType()->getAs()->getReturnType();
+  QualType BaseReturnTy = BaseMD->getType()
+  ->getAs()
+  ->getReturnType()
+  .getCanonicalType();
+  QualType DerivedReturnTy = DerivedMD->getType()
+ ->getAs()
+ ->getReturnType()
+ .getCanonicalType();
 
   if (DerivedReturnTy->isDependentType() || BaseReturnTy->isDependentType())
 return false;
@@ -54,8 +64,8 @@
   /// BTy is the class type in return type of BaseMD. For example,
   ///B* Base::md()
   /// While BRD is the declaration of B.
-  QualType DTy = DerivedReturnTy->getPointeeType();
-  QualType BTy = BaseReturnTy->getPointeeType();
+  QualType DTy = DerivedReturnTy->getPointeeType().getCanonicalType();
+  QualType BTy = BaseReturnTy->getPointeeType().getCanonicalType();
 
   const CXXRecordDecl *DRD = DTy->getAsCXXRecordDecl();
   const CXXRecordDecl *BRD = BTy->getAsCXXRecordDecl();
@@ -81,7 +91,8 @@
 // Check accessibility.
 // FIXME: We currently only support checking if B is accessible base class
 // of D, or D is the same class which DerivedMD is in.
-bool IsItself = DRD == DerivedMD->getParent();
+bool IsItself =
+DRD->getCanonicalDecl() == DerivedMD->getParent()->getCanonicalDecl();
 bool HasPublicAccess = false;
 for (const auto &Path : Paths) {
   if (Path.Access == AS_public)
@@ -121,8 +132,9 @@
 return false;
 
   for (unsigned I = 0; I < NumParamA; I++) {
-if (getDecayedType(BaseMD->getParamDecl(I)->getType()) !=
-

[PATCH] D15571: Add namespace support to add_new_check.py

2015-12-16 Thread Cong Liu via cfe-commits
congliu created this revision.
congliu added a reviewer: alexfh.
congliu added a subscriber: cfe-commits.

Without namespace you can not create checks with same name in different modules

http://reviews.llvm.org/D15571

Files:
  clang-tidy/add_new_check.py

Index: clang-tidy/add_new_check.py
===
--- clang-tidy/add_new_check.py
+++ clang-tidy/add_new_check.py
@@ -73,6 +73,7 @@
 
 namespace clang {
 namespace tidy {
+namespace %(namespace)s {
 
 /// FIXME: Write a short description.
 ///
@@ -86,18 +87,20 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 };
 
+} // namespace %(namespace)s
 } // namespace tidy
 } // namespace clang
 
 #endif // %(header_guard)s
 
 """ % {'header_guard': header_guard,
'check_name': check_name_camel,
-   'check_name_dashes': check_name_dashes})
+   'check_name_dashes': check_name_dashes,
+   'namespace': module})
 
 
 # Adds the implementation of the new check.
-def write_implementation(module_path, check_name_camel):
+def write_implementation(module_path, module,  check_name_camel):
   filename = os.path.join(module_path, check_name_camel) + '.cpp'
   print('Creating %s...' % filename)
   with open(filename, 'wb') as f:
@@ -123,6 +126,7 @@
 
 namespace clang {
 namespace tidy {
+namespace %(namespace)s {
 
 void %(check_name)s::registerMatchers(MatchFinder *Finder) {
   // FIXME: Add matchers.
@@ -139,10 +143,12 @@
   << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
 }
 
+} // namespace %(namespace)s
 } // namespace tidy
 } // namespace clang
 
-""" % {'check_name': check_name_camel})
+""" % {'check_name': check_name_camel,
+   'namespace': module})
 
 
 # Modifies the module to include the new check.
@@ -261,7 +267,7 @@
   if not adapt_cmake(module_path, check_name_camel):
 return
   write_header(module_path, module, check_name, check_name_camel)
-  write_implementation(module_path, check_name_camel)
+  write_implementation(module_path, module, check_name_camel)
   adapt_module(module_path, module, check_name, check_name_camel)
   write_test(module_path, module, check_name)
   write_docs(module_path, module, check_name)


Index: clang-tidy/add_new_check.py
===
--- clang-tidy/add_new_check.py
+++ clang-tidy/add_new_check.py
@@ -73,6 +73,7 @@
 
 namespace clang {
 namespace tidy {
+namespace %(namespace)s {
 
 /// FIXME: Write a short description.
 ///
@@ -86,18 +87,20 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 };
 
+} // namespace %(namespace)s
 } // namespace tidy
 } // namespace clang
 
 #endif // %(header_guard)s
 
 """ % {'header_guard': header_guard,
'check_name': check_name_camel,
-   'check_name_dashes': check_name_dashes})
+   'check_name_dashes': check_name_dashes,
+   'namespace': module})
 
 
 # Adds the implementation of the new check.
-def write_implementation(module_path, check_name_camel):
+def write_implementation(module_path, module,  check_name_camel):
   filename = os.path.join(module_path, check_name_camel) + '.cpp'
   print('Creating %s...' % filename)
   with open(filename, 'wb') as f:
@@ -123,6 +126,7 @@
 
 namespace clang {
 namespace tidy {
+namespace %(namespace)s {
 
 void %(check_name)s::registerMatchers(MatchFinder *Finder) {
   // FIXME: Add matchers.
@@ -139,10 +143,12 @@
   << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
 }
 
+} // namespace %(namespace)s
 } // namespace tidy
 } // namespace clang
 
-""" % {'check_name': check_name_camel})
+""" % {'check_name': check_name_camel,
+   'namespace': module})
 
 
 # Modifies the module to include the new check.
@@ -261,7 +267,7 @@
   if not adapt_cmake(module_path, check_name_camel):
 return
   write_header(module_path, module, check_name, check_name_camel)
-  write_implementation(module_path, check_name_camel)
+  write_implementation(module_path, module, check_name_camel)
   adapt_module(module_path, module, check_name, check_name_camel)
   write_test(module_path, module, check_name)
   write_docs(module_path, module, check_name)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15571: Add namespace support to add_new_check.py

2015-12-16 Thread Cong Liu via cfe-commits
congliu updated this revision to Diff 43007.
congliu added a comment.

Replaced namespace with module;
Removed extra space after module at line 103


http://reviews.llvm.org/D15571

Files:
  clang-tidy/add_new_check.py

Index: clang-tidy/add_new_check.py
===
--- clang-tidy/add_new_check.py
+++ clang-tidy/add_new_check.py
@@ -73,6 +73,7 @@
 
 namespace clang {
 namespace tidy {
+namespace %(module)s {
 
 /// FIXME: Write a short description.
 ///
@@ -86,18 +87,20 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 };
 
+} // namespace %(module)s
 } // namespace tidy
 } // namespace clang
 
 #endif // %(header_guard)s
 
 """ % {'header_guard': header_guard,
'check_name': check_name_camel,
-   'check_name_dashes': check_name_dashes})
+   'check_name_dashes': check_name_dashes,
+   'module': module})
 
 
 # Adds the implementation of the new check.
-def write_implementation(module_path, check_name_camel):
+def write_implementation(module_path, module, check_name_camel):
   filename = os.path.join(module_path, check_name_camel) + '.cpp'
   print('Creating %s...' % filename)
   with open(filename, 'wb') as f:
@@ -123,6 +126,7 @@
 
 namespace clang {
 namespace tidy {
+namespace %(module)s {
 
 void %(check_name)s::registerMatchers(MatchFinder *Finder) {
   // FIXME: Add matchers.
@@ -139,10 +143,12 @@
   << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
 }
 
+} // namespace %(module)s
 } // namespace tidy
 } // namespace clang
 
-""" % {'check_name': check_name_camel})
+""" % {'check_name': check_name_camel,
+   'module': module})
 
 
 # Modifies the module to include the new check.
@@ -261,7 +267,7 @@
   if not adapt_cmake(module_path, check_name_camel):
 return
   write_header(module_path, module, check_name, check_name_camel)
-  write_implementation(module_path, check_name_camel)
+  write_implementation(module_path, module, check_name_camel)
   adapt_module(module_path, module, check_name, check_name_camel)
   write_test(module_path, module, check_name)
   write_docs(module_path, module, check_name)


Index: clang-tidy/add_new_check.py
===
--- clang-tidy/add_new_check.py
+++ clang-tidy/add_new_check.py
@@ -73,6 +73,7 @@
 
 namespace clang {
 namespace tidy {
+namespace %(module)s {
 
 /// FIXME: Write a short description.
 ///
@@ -86,18 +87,20 @@
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 };
 
+} // namespace %(module)s
 } // namespace tidy
 } // namespace clang
 
 #endif // %(header_guard)s
 
 """ % {'header_guard': header_guard,
'check_name': check_name_camel,
-   'check_name_dashes': check_name_dashes})
+   'check_name_dashes': check_name_dashes,
+   'module': module})
 
 
 # Adds the implementation of the new check.
-def write_implementation(module_path, check_name_camel):
+def write_implementation(module_path, module, check_name_camel):
   filename = os.path.join(module_path, check_name_camel) + '.cpp'
   print('Creating %s...' % filename)
   with open(filename, 'wb') as f:
@@ -123,6 +126,7 @@
 
 namespace clang {
 namespace tidy {
+namespace %(module)s {
 
 void %(check_name)s::registerMatchers(MatchFinder *Finder) {
   // FIXME: Add matchers.
@@ -139,10 +143,12 @@
   << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
 }
 
+} // namespace %(module)s
 } // namespace tidy
 } // namespace clang
 
-""" % {'check_name': check_name_camel})
+""" % {'check_name': check_name_camel,
+   'module': module})
 
 
 # Modifies the module to include the new check.
@@ -261,7 +267,7 @@
   if not adapt_cmake(module_path, check_name_camel):
 return
   write_header(module_path, module, check_name, check_name_camel)
-  write_implementation(module_path, check_name_camel)
+  write_implementation(module_path, module, check_name_camel)
   adapt_module(module_path, module, check_name, check_name_camel)
   write_test(module_path, module, check_name)
   write_docs(module_path, module, check_name)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15571: Add namespace support to add_new_check.py

2015-12-16 Thread Cong Liu via cfe-commits
congliu marked 2 inline comments as done.
congliu added a comment.

Replace namespace with module -- Done.
Remove extra space after module -- Done.


http://reviews.llvm.org/D15571



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits