CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
99 lines
4.6 KiB
C++
99 lines
4.6 KiB
C++
// RUN: %check_clang_tidy %s abseil-duration-addition %t -- -- -I%S/Inputs
|
|
|
|
#include "absl/time/time.h"
|
|
|
|
void f() {
|
|
absl::Time t;
|
|
int i;
|
|
|
|
i = absl::ToUnixHours(t) + 5;
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: i = absl::ToUnixHours(t + absl::Hours(5));
|
|
i = absl::ToUnixMinutes(t) + 5;
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: i = absl::ToUnixMinutes(t + absl::Minutes(5));
|
|
i = absl::ToUnixSeconds(t) + 5;
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: i = absl::ToUnixSeconds(t + absl::Seconds(5));
|
|
i = absl::ToUnixMillis(t) + 5;
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: i = absl::ToUnixMillis(t + absl::Milliseconds(5));
|
|
i = absl::ToUnixMicros(t) + 5;
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: i = absl::ToUnixMicros(t + absl::Microseconds(5));
|
|
i = absl::ToUnixNanos(t) + 5;
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: i = absl::ToUnixNanos(t + absl::Nanoseconds(5));
|
|
|
|
i = 3 + absl::ToUnixHours(t);
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: i = absl::ToUnixHours(absl::Hours(3) + t);
|
|
i = 3 + absl::ToUnixMinutes(t);
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: i = absl::ToUnixMinutes(absl::Minutes(3) + t);
|
|
i = 3 + absl::ToUnixSeconds(t);
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: i = absl::ToUnixSeconds(absl::Seconds(3) + t);
|
|
i = 3 + absl::ToUnixMillis(t);
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: i = absl::ToUnixMillis(absl::Milliseconds(3) + t);
|
|
i = 3 + absl::ToUnixMicros(t);
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: i = absl::ToUnixMicros(absl::Microseconds(3) + t);
|
|
i = 3 + absl::ToUnixNanos(t);
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: i = absl::ToUnixNanos(absl::Nanoseconds(3) + t);
|
|
|
|
// Undoing inverse conversions
|
|
i = absl::ToUnixMicros(t) + absl::ToInt64Microseconds(absl::Seconds(1));
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: i = absl::ToUnixMicros(t + absl::Seconds(1));
|
|
|
|
// Parens
|
|
i = 3 + (absl::ToUnixHours(t));
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: i = absl::ToUnixHours(absl::Hours(3) + t);
|
|
|
|
// Float folding
|
|
i = absl::ToUnixSeconds(t) + 5.0;
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: i = absl::ToUnixSeconds(t + absl::Seconds(5));
|
|
|
|
// We can rewrite the argument of the duration conversion
|
|
#define THIRTY absl::FromUnixSeconds(30)
|
|
i = absl::ToUnixSeconds(THIRTY) + 1;
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: i = absl::ToUnixSeconds(THIRTY + absl::Seconds(1));
|
|
#undef THIRTY
|
|
|
|
// Some other contexts
|
|
if (absl::ToUnixSeconds(t) + 1.0 > 10) {}
|
|
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: if (absl::ToUnixSeconds(t + absl::Seconds(1)) > 10) {}
|
|
|
|
// These should not match
|
|
i = 5 + 6;
|
|
i = absl::ToUnixSeconds(t) - 1.0;
|
|
i = absl::ToUnixSeconds(t) * 1.0;
|
|
i = absl::ToUnixSeconds(t) / 1.0;
|
|
i += absl::ToInt64Microseconds(absl::Seconds(1));
|
|
|
|
#define PLUS_FIVE(z) absl::ToUnixSeconds(z) + 5
|
|
i = PLUS_FIVE(t);
|
|
#undef PLUS_FIVE
|
|
}
|
|
|
|
// Within a templated function
|
|
template<typename T>
|
|
void foo(absl::Time t) {
|
|
int i = absl::ToUnixNanos(t) + T{};
|
|
// CHECK-MESSAGES: [[@LINE-1]]:11: warning: perform addition in the duration domain [abseil-duration-addition]
|
|
// CHECK-FIXES: int i = absl::ToUnixNanos(t + absl::Nanoseconds(T{}));
|
|
}
|
|
|
|
void g() {
|
|
absl::Time t;
|
|
foo<int>(t);
|
|
foo<double>(t);
|
|
}
|