This is an analog to the existing abseil-duration-subtraction check.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
docs/ReleaseNotes.rst | ||
---|---|---|
76 ↗ | (On Diff #183387) | Please use alphabetical order for new checks. |
clang-tidy/abseil/DurationAdditionCheck.cpp | ||
---|---|---|
22 ↗ | (On Diff #183387) | This whole file is structurally similar to the DurationSubtractionCheck.cpp equivalent (which is expected :)), maybe some parts could be refactored out? |
50 ↗ | (On Diff #183387) | The only difference between the two diag seems to be the FixItHint. I would rather refactor the diag out of the if. |
60 ↗ | (On Diff #183387) | What happens with paren-casts, are they ignored as well? (See one comment in the test-cases) |
test/clang-tidy/abseil-duration-addition.cpp | ||
28 ↗ | (On Diff #183387) | Call is on the right side, what happens for 3 + (abs::ToUnixHours(t)); |
48 ↗ | (On Diff #183387) | Is something like this i += absl::ToInt64MicroSeconds(absl::Seconds(1)); possible (syntactically and semantically)? |
clang-tidy/abseil/DurationAdditionCheck.cpp | ||
---|---|---|
22 ↗ | (On Diff #183387) | I think that most of it already has been factored out (e.g., rewriteExprFromNumberToDuration and getScaleForTimeInverse, etc) . The actual meat here is pretty light: the matcher, and then the diagnostic generation. A scaling change may also follow. Our experience has been that scaling isn't quite straight forward, as the scaling factor may have semantic meaning which changes the result, but which isn't captured by the type system. Probably not a design discussion to have here, but suffice it to say that I don't know if this is yet settled. |
50 ↗ | (On Diff #183387) | This doesn't really de-dupe very much, since the bulk of the work here is creating the FixItHint. Done. |
60 ↗ | (On Diff #183387) | Now they are. |
test/clang-tidy/abseil-duration-addition.cpp | ||
28 ↗ | (On Diff #183387) | Added this test, and updated to ignore paren casts. |
48 ↗ | (On Diff #183387) | Semantically, this is possible, but wouldn't fall under this transform, since it would require changing the type of i. |
clang-tidy/abseil/DurationAdditionCheck.cpp | ||
---|---|---|
22 ↗ | (On Diff #183387) | Your right, there is not too much to gain. Only if there are more checks coming with the same structure it makes sense to think again. |
test/clang-tidy/abseil-duration-addition.cpp | ||
84 ↗ | (On Diff #183539) | a view template test-cases would be good to have. |
test/clang-tidy/abseil-duration-addition.cpp | ||
---|---|---|
84 ↗ | (On Diff #183539) | I'm not sure I know that terminology; do you have an example? |
test/clang-tidy/abseil-duration-addition.cpp | ||
---|---|---|
84 ↗ | (On Diff #183539) | template<typename T> void foo(absl::Time t) { int i = absl::ToUnixNanos(t) + T{}; } foo<int>(t); foo<double>(t); |