S1912 FP on fmt::localtime and fmt::gmtime

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)

Hi @rotolof and welcome to our community!

Thanks for raising this issue. I confirm there is indeed a bug. You can track its progress at [CPP-4028] - Jira.

1 Like