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

Alexander Kornienko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 26 07:06:28 PDT 2018


alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

Thank you for working on this!



================
Comment at: clang-tidy/modernize/RedundantVoidArgCheck.cpp:241
+    SourceLocation End =
+        Lambda->getBody()->getLocStart().isMacroID()
+            ? Result.SourceManager
----------------
Let's pull `Lambda->getBody()->getLocStart()` to a variable to avoid repetition.


================
Comment at: clang-tidy/modernize/RedundantVoidArgCheck.cpp:242-244
+            ? Result.SourceManager
+                  ->getImmediateExpansionRange(Lambda->getBody()->getLocStart())
+                  .getBegin()
----------------
The fix looks limited to the specific test case.  Let's try other cases (see the comment below).


================
Comment at: test/clang-tidy/modernize-redundant-void-arg.cpp:454
+ // CHECK-FIXES: []()BODY;
+}
----------------
I'd like to see more tests here with different macro-related cases. These come to mind, but if you come up with more distinct cases, that would be even better:

  #define LAMBDA1 [](void){}
  (void)LAMBDA1;
  #define LAMBDA2 [](void)BODY
  (void)LAMBDA2;
  #define LAMBDA3(captures, args, body) [captures](args){body}
  (void)LAMBDA3(=, void, BODY);
  #define LAMBDA4(captures, args, body) captures args body
  (void)LAMBDA4([], (void), BODY);
  #define LAMBDAS1 \
    (void)LAMBDA1; \
    (void)LAMBDA2; \
    (void)LAMBDA3(=, void, BODY); \
    (void)LAMBDA4([], (void), BODY)

  LAMBDAS1;
  #define WRAP(...) __VA_ARGS__
  WRAP((void)WRAP(WRAP(LAMBDA4(WRAP([]), WRAP((void)), WRAP(BODY)))));
  (void)WRAP([](void){});




Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49800





More information about the cfe-commits mailing list