diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 65aeb445..80d05b39 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -31,6 +31,22 @@ class compiled_string {}; template struct is_compiled_string : std::is_base_of {}; +#ifdef __cpp_if_constexpr +# define FMT_COMPILE_IMPL(s) FMT_STRING_IMPL(s, fmt::detail::compiled_string) +#else +namespace fmt_compile_error { + template struct false_type : std::false_type {}; + + template FMT_CONSTEXPR const char* report_compile_error() { + static_assert( + false_type::value, "FMT_COMPILE requires C++17 `constexpr if` compiler support" + ); + return ""; + } +} +# define FMT_COMPILE_IMPL(s) ::fmt::detail::fmt_compile_error::report_compile_error() +#endif + /** \rst Converts a string literal *s* into a format string that will be parsed at @@ -44,7 +60,7 @@ struct is_compiled_string : std::is_base_of {}; std::string s = fmt::format(FMT_COMPILE("{}"), 42); \endrst */ -#define FMT_COMPILE(s) FMT_STRING_IMPL(s, fmt::detail::compiled_string) +#define FMT_COMPILE(s) FMT_COMPILE_IMPL(s) #if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS template struct fixed_string {