Skip to content

Commit

Permalink
Add compiler deprecation warnings for absl::ConvertDateTime() and abs…
Browse files Browse the repository at this point in the history
…l::FromDateTime().

These have been marked deprecated in the comments for some time,
(since f340f77) 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
  • Loading branch information
derekmauro authored and copybara-github committed May 17, 2023
1 parent c8b33b0 commit 07e8b2a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
22 changes: 22 additions & 0 deletions absl/base/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,28 @@
#define ABSL_DEPRECATED(message)
#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
//
// A variable declaration annotated with the `ABSL_CONST_INIT` attribute will
Expand Down
9 changes: 8 additions & 1 deletion absl/time/time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ inline int64_t FloorToUnit(absl::Duration d, absl::Duration unit) {
: q - 1;
}

ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING
inline absl::Time::Breakdown InfiniteFutureBreakdown() {
absl::Time::Breakdown bd;
bd.year = std::numeric_limits<int64_t>::max();
Expand Down Expand Up @@ -99,6 +100,7 @@ inline absl::Time::Breakdown InfinitePastBreakdown() {
bd.zone_abbr = "-00";
return bd;
}
ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING

inline absl::TimeZone::CivilInfo InfiniteFutureCivilInfo() {
TimeZone::CivilInfo ci;
Expand All @@ -120,6 +122,7 @@ inline absl::TimeZone::CivilInfo InfinitePastCivilInfo() {
return ci;
}

ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING
inline absl::TimeConversion InfiniteFutureTimeConversion() {
absl::TimeConversion tc;
tc.pre = tc.trans = tc.post = absl::InfiniteFuture();
Expand All @@ -135,6 +138,7 @@ inline TimeConversion InfinitePastTimeConversion() {
tc.normalized = true;
return tc;
}
ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING

// Makes a Time from sec, overflowing to InfiniteFuture/InfinitePast as
// necessary. If sec is min/max, then consult cs+tz to check for overflow.
Expand Down Expand Up @@ -203,6 +207,7 @@ bool FindTransition(const cctz::time_zone& tz,
// Time
//

ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING
absl::Time::Breakdown Time::In(absl::TimeZone tz) const {
if (*this == absl::InfiniteFuture()) return InfiniteFutureBreakdown();
if (*this == absl::InfinitePast()) return InfinitePastBreakdown();
Expand All @@ -227,6 +232,7 @@ absl::Time::Breakdown Time::In(absl::TimeZone tz) const {
bd.zone_abbr = al.abbr;
return bd;
}
ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING

//
// Conversions from/to other time types.
Expand Down Expand Up @@ -398,7 +404,7 @@ bool TimeZone::PrevTransition(Time t, CivilTransition* trans) const {
//
// Conversions involving time zones.
//

ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING
absl::TimeConversion ConvertDateTime(int64_t year, int mon, int day, int hour,
int min, int sec, TimeZone tz) {
// Avoids years that are too extreme for CivilSecond to normalize.
Expand Down Expand Up @@ -430,6 +436,7 @@ absl::TimeConversion ConvertDateTime(int64_t year, int mon, int day, int hour,
}
return tc;
}
ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING

absl::Time FromTM(const struct tm& tm, absl::TimeZone tz) {
civil_year_t tm_year = tm.tm_year;
Expand Down
19 changes: 13 additions & 6 deletions absl/time/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,7 @@ class Time {
// `absl::TimeZone`.
//
// Deprecated. Use `absl::TimeZone::CivilInfo`.
struct
Breakdown {
struct ABSL_DEPRECATED("Use `absl::TimeZone::CivilInfo`.") Breakdown {
int64_t year; // year (e.g., 2013)
int month; // month of year [1:12]
int day; // day of month [1:31]
Expand All @@ -829,7 +828,10 @@ class Time {
// Returns the breakdown of this instant in the given TimeZone.
//
// Deprecated. Use `absl::TimeZone::At(Time)`.
ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING
ABSL_DEPRECATED("Use `absl::TimeZone::At(Time)`.")
Breakdown In(TimeZone tz) const;
ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING

template <typename H>
friend H AbslHashValue(H h, Time t) {
Expand Down Expand Up @@ -1323,8 +1325,7 @@ ABSL_ATTRIBUTE_PURE_FUNCTION inline Time FromCivil(CivilSecond ct,
// `absl::ConvertDateTime()`. Legacy version of `absl::TimeZone::TimeInfo`.
//
// Deprecated. Use `absl::TimeZone::TimeInfo`.
struct
TimeConversion {
struct ABSL_DEPRECATED("Use `absl::TimeZone::TimeInfo`.") TimeConversion {
Time pre; // time calculated using the pre-transition offset
Time trans; // when the civil-time discontinuity occurred
Time post; // time calculated using the post-transition offset
Expand Down Expand Up @@ -1358,8 +1359,11 @@ struct
// // absl::ToCivilDay(tc.pre, tz).day() == 1
//
// 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,
int min, int sec, TimeZone tz);
ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING

// FromDateTime()
//
Expand All @@ -1376,9 +1380,12 @@ TimeConversion ConvertDateTime(int64_t year, int mon, int day, int hour,
// Deprecated. Use `absl::FromCivil(CivilSecond, TimeZone)`. Note that the
// behavior of `FromCivil()` differs from `FromDateTime()` for skipped civil
// times. If you care about that see `absl::TimeZone::At(absl::CivilSecond)`.
inline Time FromDateTime(int64_t year, int mon, int day, int hour,
int min, int sec, TimeZone tz) {
ABSL_DEPRECATED("Use `absl::FromCivil(CivilSecond, TimeZone)`.")
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;
ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING
}

// FromTM()
Expand Down

0 comments on commit 07e8b2a

Please sign in to comment.