Commit 8bb5dc43 by Yuriy Chernyshov Committed by Copybara-Service

PR #1728: Workaround broken compilation against NDK r25

Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1728

When targeting Android NDK r25 (reached EOL now, but still in some use) one gets the following error:
```
$(SOURCE_ROOT)/contrib/restricted/abseil-cpp/absl/time/time.h:1762:37: error: invalid operands to binary expression ('std::strong_ordering' and 'const std::strong_ordering')
  if (auto c = lhs_hi <=> rhs_hi; c != std::strong_ordering::equal) {
```

The error indicates the lack of `operator<=>` between two `std::strong_ordering` items.
I believe that this should be controlled by `__cpp_lib_three_way_comparison` (_Three-way comparison (library support)_, see [this article](https://en.cppreference.com/w/cpp/feature_test)), not by `__cpp_impl_three_way_comparison` (which stands for _Three-way comparison (compiler support)_).

Fixes #1725.
The problem was introduced in a2766235.

Merge 32e1d3d889859ef8a32bf3460349814a2203444c into 69c46839

Merging this change closes #1728

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1728 from georgthegreat:fix-time 32e1d3d889859ef8a32bf3460349814a2203444c
PiperOrigin-RevId: 663723253
Change-Id: I29f7d2b562cc5ad8e11cd46b538ba69acee0f314
parent 17c1a5e8
...@@ -16,14 +16,19 @@ ...@@ -16,14 +16,19 @@
#include <winsock2.h> // for timeval #include <winsock2.h> // for timeval
#endif #endif
#include "absl/base/config.h"
// For feature testing and determining which headers can be included.
#if ABSL_INTERNAL_CPLUSPLUS_LANG >= 202002L
#include <version>
#endif
#include <array> #include <array>
#include <cfloat> #include <cfloat>
#include <chrono> // NOLINT(build/c++11) #include <chrono> // NOLINT(build/c++11)
#ifdef __cpp_lib_three_way_comparison
#ifdef __cpp_impl_three_way_comparison
#include <compare> #include <compare>
#endif // __cpp_impl_three_way_comparison #endif // __cpp_lib_three_way_comparison
#include <cmath> #include <cmath>
#include <cstdint> #include <cstdint>
#include <ctime> #include <ctime>
...@@ -437,14 +442,14 @@ TEST(Duration, InfinityComparison) { ...@@ -437,14 +442,14 @@ TEST(Duration, InfinityComparison) {
EXPECT_LT(-inf, inf); EXPECT_LT(-inf, inf);
EXPECT_GT(inf, -inf); EXPECT_GT(inf, -inf);
#ifdef __cpp_impl_three_way_comparison #ifdef ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
EXPECT_EQ(inf <=> inf, std::strong_ordering::equal); EXPECT_EQ(inf <=> inf, std::strong_ordering::equal);
EXPECT_EQ(-inf <=> -inf, std::strong_ordering::equal); EXPECT_EQ(-inf <=> -inf, std::strong_ordering::equal);
EXPECT_EQ(-inf <=> inf, std::strong_ordering::less); EXPECT_EQ(-inf <=> inf, std::strong_ordering::less);
EXPECT_EQ(inf <=> -inf, std::strong_ordering::greater); EXPECT_EQ(inf <=> -inf, std::strong_ordering::greater);
EXPECT_EQ(any_dur <=> inf, std::strong_ordering::less); EXPECT_EQ(any_dur <=> inf, std::strong_ordering::less);
EXPECT_EQ(any_dur <=> -inf, std::strong_ordering::greater); EXPECT_EQ(any_dur <=> -inf, std::strong_ordering::greater);
#endif // __cpp_impl_three_way_comparison #endif // ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
} }
TEST(Duration, InfinityAddition) { TEST(Duration, InfinityAddition) {
...@@ -511,18 +516,18 @@ TEST(Duration, InfinitySubtraction) { ...@@ -511,18 +516,18 @@ TEST(Duration, InfinitySubtraction) {
absl::Duration almost_neg_inf = sec_min; absl::Duration almost_neg_inf = sec_min;
EXPECT_LT(-inf, almost_neg_inf); EXPECT_LT(-inf, almost_neg_inf);
#ifdef __cpp_impl_three_way_comparison #ifdef ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
EXPECT_EQ(-inf <=> almost_neg_inf, std::strong_ordering::less); EXPECT_EQ(-inf <=> almost_neg_inf, std::strong_ordering::less);
EXPECT_EQ(almost_neg_inf <=> -inf, std::strong_ordering::greater); EXPECT_EQ(almost_neg_inf <=> -inf, std::strong_ordering::greater);
#endif // __cpp_impl_three_way_comparison #endif // ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
almost_neg_inf -= -absl::Nanoseconds(1); almost_neg_inf -= -absl::Nanoseconds(1);
EXPECT_LT(-inf, almost_neg_inf); EXPECT_LT(-inf, almost_neg_inf);
#ifdef __cpp_impl_three_way_comparison #ifdef ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
EXPECT_EQ(-inf <=> almost_neg_inf, std::strong_ordering::less); EXPECT_EQ(-inf <=> almost_neg_inf, std::strong_ordering::less);
EXPECT_EQ(almost_neg_inf <=> -inf, std::strong_ordering::greater); EXPECT_EQ(almost_neg_inf <=> -inf, std::strong_ordering::greater);
#endif // __cpp_impl_three_way_comparison #endif // ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
// For reference: IEEE 754 behavior // For reference: IEEE 754 behavior
const double dbl_inf = std::numeric_limits<double>::infinity(); const double dbl_inf = std::numeric_limits<double>::infinity();
...@@ -883,7 +888,7 @@ TEST(Duration, Range) { ...@@ -883,7 +888,7 @@ TEST(Duration, Range) {
EXPECT_LT(neg_full_range, full_range); EXPECT_LT(neg_full_range, full_range);
EXPECT_EQ(neg_full_range, -full_range); EXPECT_EQ(neg_full_range, -full_range);
#ifdef __cpp_impl_three_way_comparison #ifdef ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
EXPECT_EQ(range_future <=> absl::InfiniteDuration(), EXPECT_EQ(range_future <=> absl::InfiniteDuration(),
std::strong_ordering::less); std::strong_ordering::less);
EXPECT_EQ(range_past <=> -absl::InfiniteDuration(), EXPECT_EQ(range_past <=> -absl::InfiniteDuration(),
...@@ -896,7 +901,7 @@ TEST(Duration, Range) { ...@@ -896,7 +901,7 @@ TEST(Duration, Range) {
std::strong_ordering::greater); std::strong_ordering::greater);
EXPECT_EQ(neg_full_range <=> full_range, std::strong_ordering::less); EXPECT_EQ(neg_full_range <=> full_range, std::strong_ordering::less);
EXPECT_EQ(neg_full_range <=> -full_range, std::strong_ordering::equal); EXPECT_EQ(neg_full_range <=> -full_range, std::strong_ordering::equal);
#endif // __cpp_impl_three_way_comparison #endif // ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
} }
TEST(Duration, RelationalOperators) { TEST(Duration, RelationalOperators) {
...@@ -920,8 +925,7 @@ TEST(Duration, RelationalOperators) { ...@@ -920,8 +925,7 @@ TEST(Duration, RelationalOperators) {
#undef TEST_REL_OPS #undef TEST_REL_OPS
} }
#ifdef ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
#ifdef __cpp_impl_three_way_comparison
TEST(Duration, SpaceshipOperators) { TEST(Duration, SpaceshipOperators) {
#define TEST_REL_OPS(UNIT) \ #define TEST_REL_OPS(UNIT) \
...@@ -939,7 +943,7 @@ TEST(Duration, SpaceshipOperators) { ...@@ -939,7 +943,7 @@ TEST(Duration, SpaceshipOperators) {
#undef TEST_REL_OPS #undef TEST_REL_OPS
} }
#endif // __cpp_impl_three_way_comparison #endif // ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
TEST(Duration, Addition) { TEST(Duration, Addition) {
#define TEST_ADD_OPS(UNIT) \ #define TEST_ADD_OPS(UNIT) \
......
...@@ -74,13 +74,19 @@ ...@@ -74,13 +74,19 @@
// including 'windows.h' so we are picking the lesser of two evils here. // including 'windows.h' so we are picking the lesser of two evils here.
struct timeval; struct timeval;
#endif #endif
#include <chrono> // NOLINT(build/c++11)
#ifdef __cpp_impl_three_way_comparison #include "absl/base/config.h"
#include <compare>
#endif // __cpp_impl_three_way_comparison
// For feature testing and determining which headers can be included.
#if ABSL_INTERNAL_CPLUSPLUS_LANG >= 202002L
#include <version>
#endif
#include <chrono> // NOLINT(build/c++11)
#include <cmath> #include <cmath>
#ifdef __cpp_lib_three_way_comparison
#include <compare>
#endif // __cpp_lib_three_way_comparison
#include <cstdint> #include <cstdint>
#include <ctime> #include <ctime>
#include <limits> #include <limits>
...@@ -91,12 +97,16 @@ struct timeval; ...@@ -91,12 +97,16 @@ struct timeval;
#include <utility> #include <utility>
#include "absl/base/attributes.h" #include "absl/base/attributes.h"
#include "absl/base/config.h"
#include "absl/base/macros.h" #include "absl/base/macros.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "absl/time/civil_time.h" #include "absl/time/civil_time.h"
#include "absl/time/internal/cctz/include/cctz/time_zone.h" #include "absl/time/internal/cctz/include/cctz/time_zone.h"
#if defined(__cpp_impl_three_way_comparison) && \
defined(__cpp_lib_three_way_comparison)
#define ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON 1
#endif
namespace absl { namespace absl {
ABSL_NAMESPACE_BEGIN ABSL_NAMESPACE_BEGIN
...@@ -313,12 +323,12 @@ class Duration { ...@@ -313,12 +323,12 @@ class Duration {
// Relational Operators // Relational Operators
#ifdef __cpp_impl_three_way_comparison #ifdef ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr std::strong_ordering operator<=>( ABSL_ATTRIBUTE_CONST_FUNCTION constexpr std::strong_ordering operator<=>(
Duration lhs, Duration rhs); Duration lhs, Duration rhs);
#endif // __cpp_impl_three_way_comparison #endif // ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator<(Duration lhs, ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator<(Duration lhs,
Duration rhs); Duration rhs);
...@@ -853,9 +863,9 @@ class Time { ...@@ -853,9 +863,9 @@ class Time {
friend constexpr Time time_internal::FromUnixDuration(Duration d); friend constexpr Time time_internal::FromUnixDuration(Duration d);
friend constexpr Duration time_internal::ToUnixDuration(Time t); friend constexpr Duration time_internal::ToUnixDuration(Time t);
#ifdef __cpp_impl_three_way_comparison #ifdef ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
friend constexpr std::strong_ordering operator<=>(Time lhs, Time rhs); friend constexpr std::strong_ordering operator<=>(Time lhs, Time rhs);
#endif // __cpp_impl_three_way_comparison #endif // ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
friend constexpr bool operator<(Time lhs, Time rhs); friend constexpr bool operator<(Time lhs, Time rhs);
friend constexpr bool operator==(Time lhs, Time rhs); friend constexpr bool operator==(Time lhs, Time rhs);
...@@ -868,14 +878,14 @@ class Time { ...@@ -868,14 +878,14 @@ class Time {
}; };
// Relational Operators // Relational Operators
#ifdef __cpp_impl_three_way_comparison #ifdef ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr std::strong_ordering operator<=>( ABSL_ATTRIBUTE_CONST_FUNCTION constexpr std::strong_ordering operator<=>(
Time lhs, Time rhs) { Time lhs, Time rhs) {
return lhs.rep_ <=> rhs.rep_; return lhs.rep_ <=> rhs.rep_;
} }
#endif // __cpp_impl_three_way_comparison #endif // ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator<(Time lhs, Time rhs) { ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator<(Time lhs, Time rhs) {
return lhs.rep_ < rhs.rep_; return lhs.rep_ < rhs.rep_;
...@@ -1752,8 +1762,7 @@ ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator<(Duration lhs, ...@@ -1752,8 +1762,7 @@ ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator<(Duration lhs,
: time_internal::GetRepLo(lhs) < time_internal::GetRepLo(rhs); : time_internal::GetRepLo(lhs) < time_internal::GetRepLo(rhs);
} }
#ifdef ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
#ifdef __cpp_impl_three_way_comparison
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr std::strong_ordering operator<=>( ABSL_ATTRIBUTE_CONST_FUNCTION constexpr std::strong_ordering operator<=>(
Duration lhs, Duration rhs) { Duration lhs, Duration rhs) {
...@@ -1769,7 +1778,7 @@ ABSL_ATTRIBUTE_CONST_FUNCTION constexpr std::strong_ordering operator<=>( ...@@ -1769,7 +1778,7 @@ ABSL_ATTRIBUTE_CONST_FUNCTION constexpr std::strong_ordering operator<=>(
: lhs_lo <=> rhs_lo; : lhs_lo <=> rhs_lo;
} }
#endif // __cpp_impl_three_way_comparison #endif // ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator==(Duration lhs, ABSL_ATTRIBUTE_CONST_FUNCTION constexpr bool operator==(Duration lhs,
Duration rhs) { Duration rhs) {
......
...@@ -13,25 +13,28 @@ ...@@ -13,25 +13,28 @@
// limitations under the License. // limitations under the License.
#include "absl/time/time.h" #include "absl/time/time.h"
#include <cstdint>
#include <ios>
#include "absl/time/civil_time.h" #include "absl/time/civil_time.h"
#if defined(_MSC_VER) #if defined(_MSC_VER)
#include <winsock2.h> // for timeval #include <winsock2.h> // for timeval
#endif #endif
#include <chrono> // NOLINT(build/c++11) #include "absl/base/config.h"
#ifdef __cpp_impl_three_way_comparison // For feature testing and determining which headers can be included.
#include <compare> #if ABSL_INTERNAL_CPLUSPLUS_LANG >= 202002L
#endif // __cpp_impl_three_way_comparison #include <version>
#endif
#include <chrono> // NOLINT(build/c++11)
#ifdef __cpp_lib_three_way_comparison
#include <compare>
#endif // __cpp_lib_three_way_comparison
#include <cstdint>
#include <cstring> #include <cstring>
#include <ctime> #include <ctime>
#include <iomanip> #include <iomanip>
#include <ios>
#include <limits> #include <limits>
#include <string> #include <string>
...@@ -213,7 +216,7 @@ TEST(Time, RelationalOperators) { ...@@ -213,7 +216,7 @@ TEST(Time, RelationalOperators) {
static_assert(t1 >= t1, ""); static_assert(t1 >= t1, "");
static_assert(t3 >= t1, ""); static_assert(t3 >= t1, "");
#ifdef __cpp_impl_three_way_comparison #ifdef ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
static_assert((t1 <=> t1) == std::strong_ordering::equal, ""); static_assert((t1 <=> t1) == std::strong_ordering::equal, "");
static_assert((t2 <=> t2) == std::strong_ordering::equal, ""); static_assert((t2 <=> t2) == std::strong_ordering::equal, "");
...@@ -227,7 +230,7 @@ TEST(Time, RelationalOperators) { ...@@ -227,7 +230,7 @@ TEST(Time, RelationalOperators) {
static_assert((t3 <=> t2) == std::strong_ordering::greater, ""); static_assert((t3 <=> t2) == std::strong_ordering::greater, "");
static_assert((t3 <=> t1) == std::strong_ordering::greater, ""); static_assert((t3 <=> t1) == std::strong_ordering::greater, "");
#endif // __cpp_impl_three_way_comparison #endif // ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
} }
TEST(Time, Infinity) { TEST(Time, Infinity) {
...@@ -239,14 +242,14 @@ TEST(Time, Infinity) { ...@@ -239,14 +242,14 @@ TEST(Time, Infinity) {
static_assert(ipast < ifuture, ""); static_assert(ipast < ifuture, "");
static_assert(ifuture > ipast, ""); static_assert(ifuture > ipast, "");
#ifdef __cpp_impl_three_way_comparison #ifdef ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
static_assert((ifuture <=> ifuture) == std::strong_ordering::equal, ""); static_assert((ifuture <=> ifuture) == std::strong_ordering::equal, "");
static_assert((ipast <=> ipast) == std::strong_ordering::equal, ""); static_assert((ipast <=> ipast) == std::strong_ordering::equal, "");
static_assert((ipast <=> ifuture) == std::strong_ordering::less, ""); static_assert((ipast <=> ifuture) == std::strong_ordering::less, "");
static_assert((ifuture <=> ipast) == std::strong_ordering::greater, ""); static_assert((ifuture <=> ipast) == std::strong_ordering::greater, "");
#endif // __cpp_impl_three_way_comparison #endif // ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
// Arithmetic saturates // Arithmetic saturates
EXPECT_EQ(ifuture, ifuture + absl::Seconds(1)); EXPECT_EQ(ifuture, ifuture + absl::Seconds(1));
...@@ -263,14 +266,14 @@ TEST(Time, Infinity) { ...@@ -263,14 +266,14 @@ TEST(Time, Infinity) {
static_assert(t < ifuture, ""); static_assert(t < ifuture, "");
static_assert(t > ipast, ""); static_assert(t > ipast, "");
#ifdef __cpp_impl_three_way_comparison #ifdef ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
static_assert((t <=> ifuture) == std::strong_ordering::less, ""); static_assert((t <=> ifuture) == std::strong_ordering::less, "");
static_assert((t <=> ipast) == std::strong_ordering::greater, ""); static_assert((t <=> ipast) == std::strong_ordering::greater, "");
static_assert((ipast <=> t) == std::strong_ordering::less, ""); static_assert((ipast <=> t) == std::strong_ordering::less, "");
static_assert((ifuture <=> t) == std::strong_ordering::greater, ""); static_assert((ifuture <=> t) == std::strong_ordering::greater, "");
#endif // __cpp_impl_three_way_comparison #endif // ABSL_INTERNAL_TIME_HAS_THREE_WAY_COMPARISON
EXPECT_EQ(ifuture, t + absl::InfiniteDuration()); EXPECT_EQ(ifuture, t + absl::InfiniteDuration());
EXPECT_EQ(ipast, t - absl::InfiniteDuration()); EXPECT_EQ(ipast, t - absl::InfiniteDuration());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment