[PATCH] D21059: [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:51:13 PDT 2016


hokein updated this revision to Diff 59843.
hokein marked an inline comment as done.
hokein added a comment.

Use the existing test file.


http://reviews.llvm.org/D21059

Files:
  clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  test/clang-tidy/misc-definitions-in-headers.hpp

Index: test/clang-tidy/misc-definitions-in-headers.hpp
===================================================================
--- test/clang-tidy/misc-definitions-in-headers.hpp
+++ test/clang-tidy/misc-definitions-in-headers.hpp
@@ -103,6 +103,8 @@
 // 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;
Index: clang-tidy/misc/DefinitionsInHeadersCheck.cpp
===================================================================
--- clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -53,15 +53,17 @@
 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"),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21059.59843.patch
Type: text/x-patch
Size: 1892 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160607/11f08508/attachment.bin>


More information about the cfe-commits mailing list