[PATCH] D55784: [clang-tidy] Update abseil-duration-comparison to handle macro arguments

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 19 06:14:39 PST 2018


aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

In D55784#1334929 <https://reviews.llvm.org/D55784#1334929>, @hwright wrote:

> @aaron.ballman I am both grateful and sad that I don't possess the same macro creativity as you do. :)


LOL

> (I'm also sad that the various clang APIs aren't as well documented as I hoped.  The current solution works well, but it took a while and a bit of consultation with some other llvm'ers to get it right.)

As you dig into APIs like that, feel free to propose or commit new documentation that helps clarify things -- more/better docs are always appreciated!

LGTM with a minor commenting nit.



================
Comment at: test/clang-tidy/abseil-duration-comparison.cpp:146
+#define VALUE_IF_2(e) (e)
+#define VALUE_IF(v, e, type) (v ? VALUE_IF_2(absl::To##type##Seconds(e)) : 0)
+  int a3 = VALUE_IF(1, d1, Double);
----------------
hwright wrote:
> aaron.ballman wrote:
> > What if this is changed to:
> > ```
> > #define VALUE_IF(v, e, type) (v ? (5 > VALUE_IF_2(absl::To##type##Seconds(e))) : 0)
> > ```
> This also doesn't transform.
Fantastic, thank you! I wouldn't expect a fix-it there due to the macro shenanigans, but I'm surprised it does not diagnose given that it expands to basically the same thing as `a` and `a2` above: https://godbolt.org/z/D1MvGX (ignore the errors but look at the macro expansion from the diagnostics).

Granted, this situation is uncommon enough, so feel free to add a FIXME comment to the `a4` test case to say that it probably should be diagnosed without a fix-it hint (assuming you agree).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55784/new/

https://reviews.llvm.org/D55784





More information about the cfe-commits mailing list