[clang-tools-extra] r271991 - [clang-tidy] Ignore the deleted function in misc-definitions-in-headers.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 7 01:55:38 PDT 2016


Author: hokein
Date: Tue Jun  7 03:55:38 2016
New Revision: 271991

URL: http://llvm.org/viewvc/llvm-project?rev=271991&view=rev
Log:
[clang-tidy] Ignore the deleted function in misc-definitions-in-headers.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D21059

Modified:
    clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp?rev=271991&r1=271990&r2=271991&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp Tue Jun  7 03:55:38 2016
@@ -53,15 +53,17 @@ void DefinitionsInHeadersCheck::storeOpt
 void DefinitionsInHeadersCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus)
     return;
+  auto DefinitionMatcher =
+      anyOf(functionDecl(isDefinition(), unless(isDeleted())),
+            varDecl(isDefinition()));
   if (UseHeaderFileExtension) {
-    Finder->addMatcher(
-        namedDecl(anyOf(functionDecl(isDefinition()), varDecl(isDefinition())),
-                  usesHeaderFileExtension(HeaderFileExtensions))
-            .bind("name-decl"),
-        this);
+    Finder->addMatcher(namedDecl(DefinitionMatcher,
+                                 usesHeaderFileExtension(HeaderFileExtensions))
+                           .bind("name-decl"),
+                       this);
   } else {
     Finder->addMatcher(
-        namedDecl(anyOf(functionDecl(isDefinition()), varDecl(isDefinition())),
+        namedDecl(DefinitionMatcher,
                   anyOf(usesHeaderFileExtension(HeaderFileExtensions),
                         unless(isExpansionInMainFile())))
             .bind("name-decl"),

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp?rev=271991&r1=271990&r2=271991&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-definitions-in-headers.hpp Tue Jun  7 03:55:38 2016
@@ -103,6 +103,8 @@ namespace {
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: function 'f7' defined in a header file;
 }
 
+int f8() = delete; // OK: the function being marked delete is not callable.
+
 int a = 1;
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'a' defined in a header file; variable definitions in header files can lead to ODR violations [misc-definitions-in-headers]
 CA a1;




More information about the cfe-commits mailing list