Catch2 icon indicating copy to clipboard operation
Catch2 copied to clipboard

The chrono stringmaker implicitly assumes that the duration is default

Open gabm opened this issue 2 years ago • 0 comments

Describe the bug

I cant compile a test case with a "non-standard time_point" (see blow) against catch v3. The bug is present in catch v2, but there the stringmaker for chrono was disabled.

Expected behavior

it should compile :)

Reproduction steps

TEST_CASE("chrono") {
	std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> tp1, tp2;
	CHECK(tp1 == tp2);
}

Platform information:

  • OS: Windows 10
  • Compiler+version: vs2019
  • Catch version: v3.3.2

Additional context

  • The Problem is in https://github.com/catchorg/Catch2/blob/devel/src/catch2/catch_tostring.hpp#LL627C39-L627C39
  • to_time_t assumes a timestamp with the same duration as the standard system_clock
  • on windows, this duration is 100/ns - but I have time_points with a duration of 1ns
  • a solution could be to cast: auto converted = std::chrono::system_clock::to_time_t(std::chrono::time_point_cast<std::chrono::system_clock::duration>(time_point));

gabm avatar May 11 '23 13:05 gabm