[PATCH] D24845: [clang-tidy] fix for NOLINT after macro expansion

Matthias Gehre via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 24 09:15:52 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL282330: [clang-tidy] fix for NOLINT after macro expansion (authored by mgehre).

Changed prior to commit:
  https://reviews.llvm.org/D24845?vs=72214&id=72391#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24845

Files:
  clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/trunk/test/clang-tidy/nolint.cpp

Index: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -294,12 +294,24 @@
   return false;
 }
 
+static bool LineIsMarkedWithNOLINTinMacro(SourceManager &SM,
+                                          SourceLocation Loc) {
+  while (true) {
+    if (LineIsMarkedWithNOLINT(SM, Loc))
+      return true;
+    if (!Loc.isMacroID())
+      return false;
+    Loc = SM.getImmediateExpansionRange(Loc).first;
+  }
+  return false;
+}
+
 void ClangTidyDiagnosticConsumer::HandleDiagnostic(
     DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) {
   if (Info.getLocation().isValid() &&
       DiagLevel != DiagnosticsEngine::Error &&
       DiagLevel != DiagnosticsEngine::Fatal &&
-      LineIsMarkedWithNOLINT(Diags->getSourceManager(), Info.getLocation())) {
+      LineIsMarkedWithNOLINTinMacro(Diags->getSourceManager(), Info.getLocation())) {
     ++Context.Stats.ErrorsIgnoredNOLINT;
     return;
   }
Index: clang-tools-extra/trunk/test/clang-tidy/nolint.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/nolint.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/nolint.cpp
@@ -13,4 +13,18 @@
   int j; // NOLINT
 }
 
-// CHECK-MESSAGES: Suppressed 3 warnings (3 NOLINT)
+#define MACRO(X) class X { X(int i); };
+MACRO(D)
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: single-argument constructors must be marked explicit
+MACRO(E) // NOLINT
+
+#define MACRO_NOARG class F { F(int i); };
+MACRO_NOARG // NOLINT
+
+#define MACRO_NOLINT class G { G(int i); }; // NOLINT
+MACRO_NOLINT
+
+#define DOUBLE_MACRO MACRO(H) // NOLINT
+DOUBLE_MACRO
+
+// CHECK-MESSAGES: Suppressed 7 warnings (7 NOLINT)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24845.72391.patch
Type: text/x-patch
Size: 1899 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160924/c4d9f065/attachment.bin>


More information about the cfe-commits mailing list