Skip to content

crimson/common: replace deprecated fmt::localtime() with localtime_r()#64465

Merged
tchaikov merged 2 commits intoceph:mainfrom
tchaikov:wip-crimson-formatter-sans-fmt-local
Jul 25, 2025
Merged

crimson/common: replace deprecated fmt::localtime() with localtime_r()#64465
tchaikov merged 2 commits intoceph:mainfrom
tchaikov:wip-crimson-formatter-sans-fmt-local

Conversation

@tchaikov
Copy link
Contributor

Replace fmt::localtime() with localtime_r() to fix build failure with fmt 11.2.0. The fmt::localtime() function was deprecated in favor of std::localtime, causing build errors when treating warnings as errors:

[1/2] Building CXX object src/crimson/CMakeFiles/crimson-common.dir/common/formatter.cc.o
/home/kefu/dev/ceph/src/crimson/common/formatter.cc: In member function ‘auto fmt::v11::formatter<std::chrono::time_point<seastar::lowres_system_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > > >::format(const seastar::lowres_system_clock::time_point&, FormatContext&) const’:
/home/kefu/dev/ceph/src/crimson/common/formatter.cc:28:41: warning: ‘tm fmt::v11::localtime(time_t)’ is deprecated [-Wdeprecated-declarations]
   28 |                           fmt::localtime(tt), milliseconds);
      |                           ~~~~~~~~~~~~~~^~~~
In file included from /home/kefu/dev/ceph/src/fmt/include/fmt/ostream.h:23,
                 from /home/kefu/dev/ceph/src/seastar/include/seastar/util/backtrace.hh:40,
                 from /home/kefu/dev/ceph/src/seastar/include/seastar/core/task.hh:25,
                 from /home/kefu/dev/ceph/src/seastar/include/seastar/core/future.hh:36,
                 from /home/kefu/dev/ceph/src/seastar/include/seastar/core/timer.hh:24,
                 from /home/kefu/dev/ceph/src/seastar/include/seastar/core/lowres_clock.hh:26,
                 from /home/kefu/dev/ceph/src/crimson/common/formatter.h:4,
                 from /home/kefu/dev/ceph/src/crimson/common/formatter.cc:4:
/home/kefu/dev/ceph/src/fmt/include/fmt/chrono.h:538:28: note: declared here
  538 | FMT_DEPRECATED inline auto localtime(std::time_t time) -> std::tm {
      |                            ^~~~~~~~~

Unlike other parts of the codebase, this implementation checks the return value of localtime_r() to preserve the error-handling behavior of fmt::localtime(), which throws on failure. Future changes may opt for consistency with the broader codebase over behavioral compatibility.

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

Replace fmt::localtime() with localtime_r() to fix build failure with
fmt 11.2.0. The fmt::localtime() function was deprecated in favor of
std::localtime, causing build errors when treating warnings as errors:

```
[1/2] Building CXX object src/crimson/CMakeFiles/crimson-common.dir/common/formatter.cc.o
/home/kefu/dev/ceph/src/crimson/common/formatter.cc: In member function ‘auto fmt::v11::formatter<std::chrono::time_point<seastar::lowres_system_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > > >::format(const seastar::lowres_system_clock::time_point&, FormatContext&) const’:
/home/kefu/dev/ceph/src/crimson/common/formatter.cc:28:41: warning: ‘tm fmt::v11::localtime(time_t)’ is deprecated [-Wdeprecated-declarations]
   28 |                           fmt::localtime(tt), milliseconds);
      |                           ~~~~~~~~~~~~~~^~~~
In file included from /home/kefu/dev/ceph/src/fmt/include/fmt/ostream.h:23,
                 from /home/kefu/dev/ceph/src/seastar/include/seastar/util/backtrace.hh:40,
                 from /home/kefu/dev/ceph/src/seastar/include/seastar/core/task.hh:25,
                 from /home/kefu/dev/ceph/src/seastar/include/seastar/core/future.hh:36,
                 from /home/kefu/dev/ceph/src/seastar/include/seastar/core/timer.hh:24,
                 from /home/kefu/dev/ceph/src/seastar/include/seastar/core/lowres_clock.hh:26,
                 from /home/kefu/dev/ceph/src/crimson/common/formatter.h:4,
                 from /home/kefu/dev/ceph/src/crimson/common/formatter.cc:4:
/home/kefu/dev/ceph/src/fmt/include/fmt/chrono.h:538:28: note: declared here
  538 | FMT_DEPRECATED inline auto localtime(std::time_t time) -> std::tm {
      |                            ^~~~~~~~~
```

Unlike other parts of the codebase, this implementation checks the return
value of localtime_r() to preserve the error-handling behavior of
fmt::localtime(), which throws on failure. Future changes may opt for
consistency with the broader codebase over behavioral compatibility.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
Since commit 686dd3d, we require fmtlib >= 8.1.1, making the
version check for fmtlib < 6.0.0 obsolete. This change removes
the unnecessary version detection code.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
Copy link
Contributor

@Matan-B Matan-B left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to clean up fmt/chrono and fmt/time includes in this file, right?
Otherwise, lgtm

@Matan-B Matan-B added this to Crimson Jul 13, 2025
@Matan-B Matan-B moved this to Needs QA in Crimson Jul 13, 2025
@tchaikov
Copy link
Contributor Author

tchaikov commented Jul 13, 2025

We should be able to clean up fmt/chrono and fmt/time includes in this file, right? Otherwise, lgtm

@Matan-B could you please be more specific on "clean up"? i did drop "#include <fmt/time.h>" in dee2000 . what else am i supposed to implement to further cleanup in this file?

@Matan-B
Copy link
Contributor

Matan-B commented Jul 13, 2025

We should be able to clean up fmt/chrono and fmt/time includes in this file, right? Otherwise, lgtm

@Matan-B could you please be more specific on "clean up"? i did drop "#include <fmt/time.h>" in dee2000 . what else am i supposed to implement to further cleanup in this file?

Missed the second commit. Thanks!

@Matan-B
Copy link
Contributor

Matan-B commented Jul 23, 2025

@tchaikov tchaikov merged commit 35a3a12 into ceph:main Jul 25, 2025
13 checks passed
@tchaikov tchaikov deleted the wip-crimson-formatter-sans-fmt-local branch July 25, 2025 08:46
@Matan-B Matan-B moved this from Needs QA to Merged (Main) in Crimson Jul 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Merged (Main)

Development

Successfully merging this pull request may close these issues.

2 participants