Commit 07e8b2a1 by Derek Mauro Committed by Copybara-Service

Add compiler deprecation warnings for absl::ConvertDateTime() and absl::FromDateTime().

These have been marked deprecated in the comments for some time,
(since f340f773) but the warnings
were never enabled.

A warning suppression is enabled for Abseil code so that when we
declare types in our code, we don't get a warning.

PiperOrigin-RevId: 532891102
Change-Id: Ife0c5696a061ea44769e02869e4e3d1196e86f9d
parent c8b33b01
...@@ -685,6 +685,28 @@ ...@@ -685,6 +685,28 @@
#define ABSL_DEPRECATED(message) #define ABSL_DEPRECATED(message)
#endif #endif
// When deprecating Abseil code, it is sometimes necessary to turn off the
// warning within Abseil, until the deprecated code is actually removed. The
// deprecated code can be surrounded with these directives to acheive that
// result.
//
// class ABSL_DEPRECATED("Use Bar instead") Foo;
//
// ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING
// Baz ComputeBazFromFoo(Foo f);
// ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING
#ifdef __GNUC__
// Clang also supports these GCC pragmas.
#define ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#define ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING \
_Pragma("GCC diagnostic pop")
#else
#define ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING
#define ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING
#endif // __GNUC__
// ABSL_CONST_INIT // ABSL_CONST_INIT
// //
// A variable declaration annotated with the `ABSL_CONST_INIT` attribute will // A variable declaration annotated with the `ABSL_CONST_INIT` attribute will
......
...@@ -66,6 +66,7 @@ inline int64_t FloorToUnit(absl::Duration d, absl::Duration unit) { ...@@ -66,6 +66,7 @@ inline int64_t FloorToUnit(absl::Duration d, absl::Duration unit) {
: q - 1; : q - 1;
} }
ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING
inline absl::Time::Breakdown InfiniteFutureBreakdown() { inline absl::Time::Breakdown InfiniteFutureBreakdown() {
absl::Time::Breakdown bd; absl::Time::Breakdown bd;
bd.year = std::numeric_limits<int64_t>::max(); bd.year = std::numeric_limits<int64_t>::max();
...@@ -99,6 +100,7 @@ inline absl::Time::Breakdown InfinitePastBreakdown() { ...@@ -99,6 +100,7 @@ inline absl::Time::Breakdown InfinitePastBreakdown() {
bd.zone_abbr = "-00"; bd.zone_abbr = "-00";
return bd; return bd;
} }
ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING
inline absl::TimeZone::CivilInfo InfiniteFutureCivilInfo() { inline absl::TimeZone::CivilInfo InfiniteFutureCivilInfo() {
TimeZone::CivilInfo ci; TimeZone::CivilInfo ci;
...@@ -120,6 +122,7 @@ inline absl::TimeZone::CivilInfo InfinitePastCivilInfo() { ...@@ -120,6 +122,7 @@ inline absl::TimeZone::CivilInfo InfinitePastCivilInfo() {
return ci; return ci;
} }
ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING
inline absl::TimeConversion InfiniteFutureTimeConversion() { inline absl::TimeConversion InfiniteFutureTimeConversion() {
absl::TimeConversion tc; absl::TimeConversion tc;
tc.pre = tc.trans = tc.post = absl::InfiniteFuture(); tc.pre = tc.trans = tc.post = absl::InfiniteFuture();
...@@ -135,6 +138,7 @@ inline TimeConversion InfinitePastTimeConversion() { ...@@ -135,6 +138,7 @@ inline TimeConversion InfinitePastTimeConversion() {
tc.normalized = true; tc.normalized = true;
return tc; return tc;
} }
ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING
// Makes a Time from sec, overflowing to InfiniteFuture/InfinitePast as // Makes a Time from sec, overflowing to InfiniteFuture/InfinitePast as
// necessary. If sec is min/max, then consult cs+tz to check for overflow. // necessary. If sec is min/max, then consult cs+tz to check for overflow.
...@@ -203,6 +207,7 @@ bool FindTransition(const cctz::time_zone& tz, ...@@ -203,6 +207,7 @@ bool FindTransition(const cctz::time_zone& tz,
// Time // Time
// //
ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING
absl::Time::Breakdown Time::In(absl::TimeZone tz) const { absl::Time::Breakdown Time::In(absl::TimeZone tz) const {
if (*this == absl::InfiniteFuture()) return InfiniteFutureBreakdown(); if (*this == absl::InfiniteFuture()) return InfiniteFutureBreakdown();
if (*this == absl::InfinitePast()) return InfinitePastBreakdown(); if (*this == absl::InfinitePast()) return InfinitePastBreakdown();
...@@ -227,6 +232,7 @@ absl::Time::Breakdown Time::In(absl::TimeZone tz) const { ...@@ -227,6 +232,7 @@ absl::Time::Breakdown Time::In(absl::TimeZone tz) const {
bd.zone_abbr = al.abbr; bd.zone_abbr = al.abbr;
return bd; return bd;
} }
ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING
// //
// Conversions from/to other time types. // Conversions from/to other time types.
...@@ -398,7 +404,7 @@ bool TimeZone::PrevTransition(Time t, CivilTransition* trans) const { ...@@ -398,7 +404,7 @@ bool TimeZone::PrevTransition(Time t, CivilTransition* trans) const {
// //
// Conversions involving time zones. // Conversions involving time zones.
// //
ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING
absl::TimeConversion ConvertDateTime(int64_t year, int mon, int day, int hour, absl::TimeConversion ConvertDateTime(int64_t year, int mon, int day, int hour,
int min, int sec, TimeZone tz) { int min, int sec, TimeZone tz) {
// Avoids years that are too extreme for CivilSecond to normalize. // Avoids years that are too extreme for CivilSecond to normalize.
...@@ -430,6 +436,7 @@ absl::TimeConversion ConvertDateTime(int64_t year, int mon, int day, int hour, ...@@ -430,6 +436,7 @@ absl::TimeConversion ConvertDateTime(int64_t year, int mon, int day, int hour,
} }
return tc; return tc;
} }
ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING
absl::Time FromTM(const struct tm& tm, absl::TimeZone tz) { absl::Time FromTM(const struct tm& tm, absl::TimeZone tz) {
civil_year_t tm_year = tm.tm_year; civil_year_t tm_year = tm.tm_year;
......
...@@ -802,8 +802,7 @@ class Time { ...@@ -802,8 +802,7 @@ class Time {
// `absl::TimeZone`. // `absl::TimeZone`.
// //
// Deprecated. Use `absl::TimeZone::CivilInfo`. // Deprecated. Use `absl::TimeZone::CivilInfo`.
struct struct ABSL_DEPRECATED("Use `absl::TimeZone::CivilInfo`.") Breakdown {
Breakdown {
int64_t year; // year (e.g., 2013) int64_t year; // year (e.g., 2013)
int month; // month of year [1:12] int month; // month of year [1:12]
int day; // day of month [1:31] int day; // day of month [1:31]
...@@ -829,7 +828,10 @@ class Time { ...@@ -829,7 +828,10 @@ class Time {
// Returns the breakdown of this instant in the given TimeZone. // Returns the breakdown of this instant in the given TimeZone.
// //
// Deprecated. Use `absl::TimeZone::At(Time)`. // Deprecated. Use `absl::TimeZone::At(Time)`.
ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING
ABSL_DEPRECATED("Use `absl::TimeZone::At(Time)`.")
Breakdown In(TimeZone tz) const; Breakdown In(TimeZone tz) const;
ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING
template <typename H> template <typename H>
friend H AbslHashValue(H h, Time t) { friend H AbslHashValue(H h, Time t) {
...@@ -1323,8 +1325,7 @@ ABSL_ATTRIBUTE_PURE_FUNCTION inline Time FromCivil(CivilSecond ct, ...@@ -1323,8 +1325,7 @@ ABSL_ATTRIBUTE_PURE_FUNCTION inline Time FromCivil(CivilSecond ct,
// `absl::ConvertDateTime()`. Legacy version of `absl::TimeZone::TimeInfo`. // `absl::ConvertDateTime()`. Legacy version of `absl::TimeZone::TimeInfo`.
// //
// Deprecated. Use `absl::TimeZone::TimeInfo`. // Deprecated. Use `absl::TimeZone::TimeInfo`.
struct struct ABSL_DEPRECATED("Use `absl::TimeZone::TimeInfo`.") TimeConversion {
TimeConversion {
Time pre; // time calculated using the pre-transition offset Time pre; // time calculated using the pre-transition offset
Time trans; // when the civil-time discontinuity occurred Time trans; // when the civil-time discontinuity occurred
Time post; // time calculated using the post-transition offset Time post; // time calculated using the post-transition offset
...@@ -1358,8 +1359,11 @@ struct ...@@ -1358,8 +1359,11 @@ struct
// // absl::ToCivilDay(tc.pre, tz).day() == 1 // // absl::ToCivilDay(tc.pre, tz).day() == 1
// //
// Deprecated. Use `absl::TimeZone::At(CivilSecond)`. // Deprecated. Use `absl::TimeZone::At(CivilSecond)`.
ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING
ABSL_DEPRECATED("Use `absl::TimeZone::At(CivilSecond)`.")
TimeConversion ConvertDateTime(int64_t year, int mon, int day, int hour, TimeConversion ConvertDateTime(int64_t year, int mon, int day, int hour,
int min, int sec, TimeZone tz); int min, int sec, TimeZone tz);
ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING
// FromDateTime() // FromDateTime()
// //
...@@ -1376,9 +1380,12 @@ TimeConversion ConvertDateTime(int64_t year, int mon, int day, int hour, ...@@ -1376,9 +1380,12 @@ TimeConversion ConvertDateTime(int64_t year, int mon, int day, int hour,
// Deprecated. Use `absl::FromCivil(CivilSecond, TimeZone)`. Note that the // Deprecated. Use `absl::FromCivil(CivilSecond, TimeZone)`. Note that the
// behavior of `FromCivil()` differs from `FromDateTime()` for skipped civil // behavior of `FromCivil()` differs from `FromDateTime()` for skipped civil
// times. If you care about that see `absl::TimeZone::At(absl::CivilSecond)`. // times. If you care about that see `absl::TimeZone::At(absl::CivilSecond)`.
inline Time FromDateTime(int64_t year, int mon, int day, int hour, ABSL_DEPRECATED("Use `absl::FromCivil(CivilSecond, TimeZone)`.")
int min, int sec, TimeZone tz) { inline Time FromDateTime(int64_t year, int mon, int day, int hour, int min,
int sec, TimeZone tz) {
ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING
return ConvertDateTime(year, mon, day, hour, min, sec, tz).pre; return ConvertDateTime(year, mon, day, hour, min, sec, tz).pre;
ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING
} }
// FromTM() // FromTM()
......
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