From: Kefu Chai Date: Sun, 8 Jun 2025 12:11:21 +0000 (+0800) Subject: include/utime_fmt.h: replace deprecated fmt::localtime() with localtime_r() X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=35fdacb01b8431acebcdf3fa812df7b4a1f6eab0;p=ceph.git include/utime_fmt.h: replace deprecated fmt::localtime() with localtime_r() Replace fmt::localtime() with localtime_r() to fix build failure with fmt 11.2.0, where fmt::localtime() was deprecated in favor of std::localtime. The deprecated function causes build errors when treating warnings as errors: ``` In file included from /home/jenkins-build/build/workspace/ceph-pull-requests/src/common/LogEntry.cc:7: In file included from /home/jenkins-build/build/workspace/ceph-pull-requests/src/common/LogEntry.h:22: /home/jenkins-build/build/workspace/ceph-pull-requests/src/include/utime_fmt.h:37:25: error: 'localtime' is deprecated [-Werror,-Wdeprecated-declarations] 37 | auto aslocal = fmt::localtime(utime.sec()); | ^ /home/jenkins-build/build/workspace/ceph-pull-requests/src/fmt/include/fmt/chrono.h:538:1: note: 'localtime' has been explicitly marked deprecated here 538 | FMT_DEPRECATED inline auto localtime(std::time_t time) -> std::tm { | ^ /home/jenkins-build/build/workspace/ceph-pull-requests/src/fmt/include/fmt/base.h:207:28: note: expanded from macro 'FMT_DEPRECATED' 207 | # define FMT_DEPRECATED [[deprecated]] | ^ 1 error generated. ``` Using localtime_r() provides thread-safe behavior with user-provided buffers instead of static storage, addressing the deprecation while maintaining functionality. See: https://github.com/fmtlib/fmt/releases/tag/11.2.0 This should address the build failure, and should prepare us for switching to fmt 11.2.0, which in turn includes a bug fix preventing us from building with Clang 20. Signed-off-by: Kefu Chai --- diff --git a/src/include/utime_fmt.h b/src/include/utime_fmt.h index 9d49d1bf050f..841f68d08d01 100644 --- a/src/include/utime_fmt.h +++ b/src/include/utime_fmt.h @@ -34,7 +34,11 @@ struct fmt::formatter { // this looks like an absolute time. // conform to http://en.wikipedia.org/wiki/ISO_8601 // (unless short_format is set) - auto aslocal = fmt::localtime(utime.sec()); + std::time_t time = utime.sec(); + std::tm aslocal; + if (!localtime_r(&time, &aslocal)) { + throw fmt::format_error("time_t value out of range"); + } if (short_format) { return fmt::format_to(ctx.out(), "{:%FT%T}.{:03}", aslocal, utime.usec() / 1000);