Index: clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h +++ clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/time/time.h @@ -0,0 +1,72 @@ +// Mimic the implementation of absl::Duration +namespace absl { + +using int64_t = long long int; + +class Duration { +public: + Duration &operator*=(int64_t r); + Duration &operator*=(float r); + Duration &operator*=(double r); + template Duration &operator*=(T r); + + Duration &operator/=(int64_t r); + Duration &operator/=(float r); + Duration &operator/=(double r); + template Duration &operator/=(T r); +}; + +template Duration operator*(Duration lhs, T rhs); +template Duration operator*(T lhs, Duration rhs); +template Duration operator/(Duration lhs, T rhs); + +class Time{}; + +constexpr Duration Nanoseconds(long long); +constexpr Duration Microseconds(long long); +constexpr Duration Milliseconds(long long); +constexpr Duration Seconds(long long); +constexpr Duration Minutes(long long); +constexpr Duration Hours(long long); + +template struct EnableIfFloatImpl {}; +template <> struct EnableIfFloatImpl { typedef int Type; }; +template <> struct EnableIfFloatImpl { typedef int Type; }; +template <> struct EnableIfFloatImpl { typedef int Type; }; +template using EnableIfFloat = typename EnableIfFloatImpl::Type; + +template = 0> Duration Nanoseconds(T n); +template = 0> Duration Microseconds(T n); +template = 0> Duration Milliseconds(T n); +template = 0> Duration Seconds(T n); +template = 0> Duration Minutes(T n); +template = 0> Duration Hours(T n); + +double ToDoubleHours(Duration d); +double ToDoubleMinutes(Duration d); +double ToDoubleSeconds(Duration d); +double ToDoubleMilliseconds(Duration d); +double ToDoubleMicroseconds(Duration d); +double ToDoubleNanoseconds(Duration d); +int64_t ToInt64Hours(Duration d); +int64_t ToInt64Minutes(Duration d); +int64_t ToInt64Seconds(Duration d); +int64_t ToInt64Milliseconds(Duration d); +int64_t ToInt64Microseconds(Duration d); +int64_t ToInt64Nanoseconds(Duration d); + +// Relational Operators +constexpr bool operator<(Duration lhs, Duration rhs); +constexpr bool operator>(Duration lhs, Duration rhs); +constexpr bool operator>=(Duration lhs, Duration rhs); +constexpr bool operator<=(Duration lhs, Duration rhs); +constexpr bool operator==(Duration lhs, Duration rhs); +constexpr bool operator!=(Duration lhs, Duration rhs); + +// Additive Operators +inline Time operator+(Time lhs, Duration rhs); +inline Time operator+(Duration lhs, Time rhs); +inline Time operator-(Time lhs, Duration rhs); +inline Duration operator-(Time lhs, Time rhs); + +} // namespace absl Index: clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp +++ clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp @@ -1,62 +1,6 @@ -// RUN: %check_clang_tidy %s abseil-duration-comparison %t +// RUN: %check_clang_tidy %s abseil-duration-comparison %t -- -- -I%S/Inputs -// Mimic the implementation of absl::Duration -namespace absl { - -class Duration {}; -class Time{}; - -Duration Nanoseconds(long long); -Duration Microseconds(long long); -Duration Milliseconds(long long); -Duration Seconds(long long); -Duration Minutes(long long); -Duration Hours(long long); - -#define GENERATE_DURATION_FACTORY_OVERLOADS(NAME) \ - Duration NAME(float n); \ - Duration NAME(double n); \ - template \ - Duration NAME(T n); - -GENERATE_DURATION_FACTORY_OVERLOADS(Nanoseconds); -GENERATE_DURATION_FACTORY_OVERLOADS(Microseconds); -GENERATE_DURATION_FACTORY_OVERLOADS(Milliseconds); -GENERATE_DURATION_FACTORY_OVERLOADS(Seconds); -GENERATE_DURATION_FACTORY_OVERLOADS(Minutes); -GENERATE_DURATION_FACTORY_OVERLOADS(Hours); -#undef GENERATE_DURATION_FACTORY_OVERLOADS - -using int64_t = long long int; - -double ToDoubleHours(Duration d); -double ToDoubleMinutes(Duration d); -double ToDoubleSeconds(Duration d); -double ToDoubleMilliseconds(Duration d); -double ToDoubleMicroseconds(Duration d); -double ToDoubleNanoseconds(Duration d); -int64_t ToInt64Hours(Duration d); -int64_t ToInt64Minutes(Duration d); -int64_t ToInt64Seconds(Duration d); -int64_t ToInt64Milliseconds(Duration d); -int64_t ToInt64Microseconds(Duration d); -int64_t ToInt64Nanoseconds(Duration d); - -// Relational Operators -constexpr bool operator<(Duration lhs, Duration rhs); -constexpr bool operator>(Duration lhs, Duration rhs); -constexpr bool operator>=(Duration lhs, Duration rhs); -constexpr bool operator<=(Duration lhs, Duration rhs); -constexpr bool operator==(Duration lhs, Duration rhs); -constexpr bool operator!=(Duration lhs, Duration rhs); - -// Additive Operators -inline Time operator+(Time lhs, Duration rhs); -inline Time operator+(Duration lhs, Time rhs); -inline Time operator-(Time lhs, Duration rhs); -inline Duration operator-(Time lhs, Time rhs); - -} // namespace absl +#include "absl/time/time.h" void f() { double x; Index: clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-float.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-float.cpp +++ clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-float.cpp @@ -1,32 +1,6 @@ -// RUN: %check_clang_tidy %s abseil-duration-factory-float %t +// RUN: %check_clang_tidy %s abseil-duration-factory-float %t -- -- -I%S/Inputs -// Mimic the implementation of absl::Duration -namespace absl { - -class Duration {}; - -Duration Nanoseconds(long long); -Duration Microseconds(long long); -Duration Milliseconds(long long); -Duration Seconds(long long); -Duration Minutes(long long); -Duration Hours(long long); - -#define GENERATE_DURATION_FACTORY_OVERLOADS(NAME) \ - Duration NAME(float n); \ - Duration NAME(double n); \ - template \ - Duration NAME(T n); - -GENERATE_DURATION_FACTORY_OVERLOADS(Nanoseconds); -GENERATE_DURATION_FACTORY_OVERLOADS(Microseconds); -GENERATE_DURATION_FACTORY_OVERLOADS(Milliseconds); -GENERATE_DURATION_FACTORY_OVERLOADS(Seconds); -GENERATE_DURATION_FACTORY_OVERLOADS(Minutes); -GENERATE_DURATION_FACTORY_OVERLOADS(Hours); -#undef GENERATE_DURATION_FACTORY_OVERLOADS - -} // namespace absl +#include "absl/time/time.h" void ConvertFloatTest() { absl::Duration d; Index: clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-scale.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-scale.cpp +++ clang-tools-extra/trunk/test/clang-tidy/abseil-duration-factory-scale.cpp @@ -1,32 +1,6 @@ -// RUN: %check_clang_tidy %s abseil-duration-factory-scale %t +// RUN: %check_clang_tidy %s abseil-duration-factory-scale %t -- -- -I%S/Inputs -// Mimic the implementation of absl::Duration -namespace absl { - -class Duration {}; - -Duration Nanoseconds(long long); -Duration Microseconds(long long); -Duration Milliseconds(long long); -Duration Seconds(long long); -Duration Minutes(long long); -Duration Hours(long long); - -#define GENERATE_DURATION_FACTORY_OVERLOADS(NAME) \ - Duration NAME(float n); \ - Duration NAME(double n); \ - template \ - Duration NAME(T n); - -GENERATE_DURATION_FACTORY_OVERLOADS(Nanoseconds); -GENERATE_DURATION_FACTORY_OVERLOADS(Microseconds); -GENERATE_DURATION_FACTORY_OVERLOADS(Milliseconds); -GENERATE_DURATION_FACTORY_OVERLOADS(Seconds); -GENERATE_DURATION_FACTORY_OVERLOADS(Minutes); -GENERATE_DURATION_FACTORY_OVERLOADS(Hours); -#undef GENERATE_DURATION_FACTORY_OVERLOADS - -} // namespace absl +#include "absl/time/time.h" void ScaleTest() { absl::Duration d; Index: clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp +++ clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp @@ -1,49 +1,8 @@ -// RUN: %check_clang_tidy %s abseil-upgrade-duration-conversions %t +// RUN: %check_clang_tidy %s abseil-upgrade-duration-conversions %t -- -- -I%S/Inputs using int64_t = long long; -// Partial implementation of relevant APIs from -// https://github.com/abseil/abseil-cpp/blob/master/absl/time/time.h -namespace absl { - -class Duration { -public: - Duration &operator*=(int64_t r); - Duration &operator*=(float r); - Duration &operator*=(double r); - template Duration &operator*=(T r); - - Duration &operator/=(int64_t r); - Duration &operator/=(float r); - Duration &operator/=(double r); - template Duration &operator/=(T r); -}; - -template Duration operator*(Duration lhs, T rhs); -template Duration operator*(T lhs, Duration rhs); -template Duration operator/(Duration lhs, T rhs); - -constexpr Duration Nanoseconds(int64_t n); -constexpr Duration Microseconds(int64_t n); -constexpr Duration Milliseconds(int64_t n); -constexpr Duration Seconds(int64_t n); -constexpr Duration Minutes(int64_t n); -constexpr Duration Hours(int64_t n); - -template struct EnableIfFloatImpl {}; -template <> struct EnableIfFloatImpl { typedef int Type; }; -template <> struct EnableIfFloatImpl { typedef int Type; }; -template <> struct EnableIfFloatImpl { typedef int Type; }; -template using EnableIfFloat = typename EnableIfFloatImpl::Type; - -template = 0> Duration Nanoseconds(T n); -template = 0> Duration Microseconds(T n); -template = 0> Duration Milliseconds(T n); -template = 0> Duration Seconds(T n); -template = 0> Duration Minutes(T n); -template = 0> Duration Hours(T n); - -} // namespace absl +#include "absl/time/time.h" template struct ConvertibleTo { operator T() const;