I’m using the fmt formatting library in my C++ projects and the functions fmt::localtime
and fmt::gmtime
trigger the rule cpp:S1912 (Non-reentrant POSIX functions should be replaced with their reentrant versions).
It’s a false positive because the functions are thread-safe (see API reference).
I’m using SonarLint for CLion, in standalone mode.
#include <fmt/chrono.h>
int main() {
auto now = std::chrono::system_clock::now();
auto timestamp = std::chrono::system_clock::to_time_t(now);
fmt::print("Time is {:%Y-%m-%d %H:%M}", fmt::localtime(timestamp));
}
fmt-localtime.zip (735 Bytes)