Repository: fmtlib/fmt
File: test/compile-test.cc (C++)

Code before:
  }
};
FMT_END_NAMESPACE

TEST(compile_test, print) {
  EXPECT_WRITE(stdout, fmt::print(FMT_COMPILE("Don't {}!"), "panic"),
               "Don't panic!");
  EXPECT_WRITE(stderr, fmt::print(stderr, FMT_COMPILE("Don't {}!"), "panic"),
               "Don't panic!");
  fmt::print(FMT_COMPILE("{}"), std_context_test());
}
#endif

#if FMT_USE_NONTYPE_TEMPLATE_ARGS
TEST(compile_test, compile_format_string_literal) {
  using namespace fmt::literals;
  EXPECT_EQ("", fmt::format(""_cf));
  EXPECT_EQ("42", fmt::format("{}"_cf, 42));
  EXPECT_EQ(L"42", fmt::format(L"{}"_cf, 42));
}
#endif

#if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction)
template <typename S>
typename fmt::is_compiled_string<S>::value_type check_is_compiled_string(
    const S&) {
  return fmt::is_compiled_string<S>::value;
}

TEST(compile_test, is_compiled_string) {
  EXPECT_TRUE(check_is_compiled_string(FMT_COMPILE("asdf")));
  EXPECT_TRUE(check_is_compiled_string(FMT_COMPILE("{}")));
}
#endif

// MSVS 2019 19.29.30145.0 - OK
// MSVS 2022 19.32.31332.0, 19.37.32826.1 - compile-test.cc(362,3): fatal error
// C1001: Internal compiler error.
//  (compiler file
//  'D:\a\_work\1\s\src\vctools\Compiler\CxxFE\sl\p1\c\constexpr\constexpr.cpp',
//  line 8635)
#if FMT_USE_CONSTEVAL &&                                     \
    (!FMT_MSC_VERSION ||                                     \
     (FMT_MSC_VERSION >= 1928 && FMT_MSC_VERSION < 1930)) && \
    defined(__cpp_lib_is_constant_evaluated)
template <size_t max_string_length, typename Char = char> struct test_string {
  template <typename T> constexpr bool operator==(const T& rhs) const noexcept {
    return fmt::basic_string_view<Char>(rhs).compare(buffer) == 0;
  }
  Char buffer[max_string_length]{};
};

Review comment (suggestion):
`value_type` is just `bool` so let's just use that for simplicity.

Code after:
  }
};
FMT_END_NAMESPACE

TEST(compile_test, print) {
  EXPECT_WRITE(stdout, fmt::print(FMT_COMPILE("Don't {}!"), "panic"),
               "Don't panic!");
  EXPECT_WRITE(stderr, fmt::print(stderr, FMT_COMPILE("Don't {}!"), "panic"),
               "Don't panic!");
  fmt::print(FMT_COMPILE("{}"), std_context_test());
}
#endif

#if FMT_USE_NONTYPE_TEMPLATE_ARGS
TEST(compile_test, compile_format_string_literal) {
  using namespace fmt::literals;
  EXPECT_EQ("", fmt::format(""_cf));
  EXPECT_EQ("42", fmt::format("{}"_cf, 42));
  EXPECT_EQ(L"42", fmt::format(L"{}"_cf, 42));
}
#endif

#if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction)
template <typename S>
bool check_is_compiled_string(const S&) {
  return fmt::is_compiled_string<S>::value;
}

TEST(compile_test, is_compiled_string) {
  EXPECT_TRUE(check_is_compiled_string(FMT_COMPILE("asdf")));
  EXPECT_TRUE(check_is_compiled_string(FMT_COMPILE("{}")));
}
#endif

// MSVS 2019 19.29.30145.0 - OK
// MSVS 2022 19.32.31332.0, 19.37.32826.1 - compile-test.cc(362,3): fatal error
// C1001: Internal compiler error.
//  (compiler file
//  'D:\a\_work\1\s\src\vctools\Compiler\CxxFE\sl\p1\c\constexpr\constexpr.cpp',
//  line 8635)
#if FMT_USE_CONSTEVAL &&                                     \
    (!FMT_MSC_VERSION ||                                     \
     (FMT_MSC_VERSION >= 1928 && FMT_MSC_VERSION < 1930)) && \
    defined(__cpp_lib_is_constant_evaluated)
template <size_t max_string_length, typename Char = char> struct test_string {
  template <typename T> constexpr bool operator==(const T& rhs) const noexcept {
    return fmt::basic_string_view<Char>(rhs).compare(buffer) == 0;
  }
  Char buffer[max_string_length]{};
};