crimson/common: replace deprecated fmt::localtime() with localtime_r()#64465
Merged
crimson/common: replace deprecated fmt::localtime() with localtime_r()#64465
Conversation
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>
14 tasks
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>
Matan-B
approved these changes
Jul 13, 2025
Contributor
Matan-B
left a comment
There was a problem hiding this comment.
We should be able to clean up fmt/chrono and fmt/time includes in this file, right?
Otherwise, lgtm
Contributor
Author
Matan-B
approved these changes
Jul 13, 2025
Contributor
Missed the second commit. Thanks! |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job Definition