[PATCH] D54737: [clang-tidy] Add the abseil-duration-comparison check

Jonas Toth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 20 02:29:46 PST 2018


JonasToth added inline comments.


================
Comment at: test/clang-tidy/abseil-duration-comparison.cpp:89
+  // CHECK-FIXES: d1 > d2;
+
+  // Check against the LHS
----------------
JonasToth wrote:
> What would happen for a type, that can implicitly convert to a duration or double/int.
> 
> ```
> struct MetaBenchmarkResults {
>     int64_t RunID;
>    absl::Duration D;
> 
>   operator absl::Duration() { return D; }
> };
> 
> auto R = MetaBenchmarkResults { /* Foo */ };
> bool WithinReason = Threshold < R;
> ```
> 
> What is the correct behaviour there? I think this should be diagnosed too.
Hmmmm, I fiddled around in godbolt, and i think there is nothing to trick around with conversions, as they wont compile.
If you find something along the lines, please tell me. But i guess this is a non-issue.

https://godbolt.org/z/gqhhHo


================
Comment at: test/clang-tidy/abseil-duration-comparison.cpp:153
+  // Other abseil-duration checks folded into this one
+  b = static_cast<double>(5) > absl::ToDoubleSeconds(d1);
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform duration comparison in the duration domain [abseil-duration-comparison]
----------------
Please test the other casts you match on as well (especially c-style)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54737





More information about the cfe-commits mailing list