[PATCH] D49800: [clang-tidy: modernize] modernize-redundant-void-arg crashes when a function body is in a macro

Idriss via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 25 08:09:36 PDT 2018


IdrissRio created this revision.
IdrissRio added reviewers: aaron.ballman, hokein, alexfh.
Herald added a subscriber: cfe-commits.

Hello, i would like to suggest a fix for one of the checks in clang-tidy. The bug was reported in https://bugs.llvm.org/show_bug.cgi?id=28406 where you can find more information.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49800

Files:
  clang-tidy/modernize/RedundantVoidArgCheck.cpp
  test/clang-tidy/modernize-redundant-void-arg.cpp


Index: test/clang-tidy/modernize-redundant-void-arg.cpp
===================================================================
--- test/clang-tidy/modernize-redundant-void-arg.cpp
+++ test/clang-tidy/modernize-redundant-void-arg.cpp
@@ -445,3 +445,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: {{.*}} in function definition
   // CHECK-FIXES: DefinitionWithNoBody() = delete;
 };
+
+#define BODY {}
+void foo_lamb(){
+ [](void)BODY;
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant void argument list in lambda expression [modernize-redundant-void-arg]
+ // CHECK-FIXES: []()BODY;
+}
Index: clang-tidy/modernize/RedundantVoidArgCheck.cpp
===================================================================
--- clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -237,7 +237,13 @@
       Lambda->hasExplicitParameters()) {
     SourceLocation Begin =
         Lambda->getIntroducerRange().getEnd().getLocWithOffset(1);
-    SourceLocation End = Lambda->getBody()->getLocStart().getLocWithOffset(-1);
+    SourceLocation End =
+        Lambda->getBody()->getLocStart().isMacroID()
+            ? Result.SourceManager
+                  ->getImmediateExpansionRange(Lambda->getBody()->getLocStart())
+                  .getBegin()
+                  .getLocWithOffset(-1)
+            : Lambda->getBody()->getLocStart().getLocWithOffset(-1);
     removeVoidArgumentTokens(Result, SourceRange(Begin, End),
                              "lambda expression");
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49800.157272.patch
Type: text/x-patch
Size: 1520 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180725/1c7b6baa/attachment.bin>


More information about the cfe-commits mailing list