@@ -414,4 +414,36 @@ TEST(std_test, format_shared_ptr) {
414414TEST (std_test, format_reference_wrapper) {
415415 int num = 35 ;
416416 EXPECT_EQ (" 35" , fmt::to_string (std::cref (num)));
417+ EXPECT_EQ (" 35" , fmt::to_string (std::ref (num)));
418+ EXPECT_EQ (" 35" , fmt::format (" {}" , std::cref (num)));
419+ EXPECT_EQ (" 35" , fmt::format (" {}" , std::ref (num)));
420+ }
421+
422+ // Regression test for https://github.com/fmtlib/fmt/issues/4424
423+ struct type_with_format_as {
424+ int x;
425+ };
426+
427+ int format_as (const type_with_format_as& t) { return t.x ; }
428+
429+ TEST (std_test, format_reference_wrapper_with_format_as) {
430+ type_with_format_as t{20 };
431+ EXPECT_EQ (" 20" , fmt::to_string (std::cref (t)));
432+ EXPECT_EQ (" 20" , fmt::to_string (std::ref (t)));
433+ EXPECT_EQ (" 20" , fmt::format (" {}" , std::cref (t)));
434+ EXPECT_EQ (" 20" , fmt::format (" {}" , std::ref (t)));
435+ }
436+
437+ struct type_with_format_as_string {
438+ std::string str;
439+ };
440+
441+ std::string format_as (const type_with_format_as_string& t) { return t.str ; }
442+
443+ TEST (std_test, format_reference_wrapper_with_format_as_string) {
444+ type_with_format_as_string t{" foo" };
445+ EXPECT_EQ (" foo" , fmt::to_string (std::cref (t)));
446+ EXPECT_EQ (" foo" , fmt::to_string (std::ref (t)));
447+ EXPECT_EQ (" foo" , fmt::format (" {}" , std::cref (t)));
448+ EXPECT_EQ (" foo" , fmt::format (" {}" , std::ref (t)));
417449}
0 commit comments