1616
1717#include < __concepts/arithmetic.h>
1818#include < __concepts/same_as.h>
19+ #include < __concepts/semiregular.h>
1920#include < __config>
2021#include < __format/concepts.h>
2122#include < __format/format_arg.h>
23+ #include < __format/format_parse_context.h>
2224#include < __type_traits/conditional.h>
2325#include < __type_traits/extent.h>
26+ #include < __type_traits/is_assignable.h>
27+ #include < __type_traits/is_constructible.h>
2428#include < __type_traits/remove_const.h>
2529#include < cstdint>
2630#include < string>
@@ -227,16 +231,6 @@ template <class _Context, class _Tp>
227231 { __f.parse (__pc) } -> same_as<typename decltype (__pc)::iterator>;
228232 };
229233
230- constexpr bool __has_format_function = requires (_Formatter& __f, _Tp&& __t , _Context __fc) {
231- { __f.format (__t , __fc) };
232- };
233- constexpr bool __is_format_function_const_qualified = requires (const _Formatter& __cf, _Tp&& __t , _Context __fc) {
234- { __cf.format (__t , __fc) };
235- };
236- constexpr bool __correct_format_function_return_type = requires (_Formatter& __f, _Tp&& __t , _Context __fc) {
237- { __f.format (__t , __fc)->same_as <typename _Context::iterator> };
238- };
239-
240234 // The reason these static_asserts are placed in an if-constexpr-chain is to
241235 // only show one error. For example, when the formatter is not specialized it
242236 // would show all static_assert messages. With this chain the compiler only
@@ -253,17 +247,37 @@ template <class _Context, class _Tp>
253247 else if constexpr (!__correct_parse_function_return_type)
254248 static_assert (false , " The required formatter specialization's parse function does not return the required type." );
255249
256- else if constexpr (!__has_format_function)
257- static_assert (
258- false , " The required formatter specialization does not have a format function taking the proper arguments." );
259- else if constexpr (!__is_format_function_const_qualified)
260- static_assert (false , " The required formatter specialization's format function is not const qualified." );
261- else if constexpr (!__correct_format_function_return_type)
262- static_assert (false , " The required formatter specialization's format function does not return the required type." );
250+ else {
251+ // During constant evaluation this function is called, but the format
252+ // member function has not been evaluated. This means these functions
253+ // can't be evaluated at that time.
254+ //
255+ // Note this else branch should never been taken during constant
256+ // eveluation, the static_asserts in one of the branches above should
257+ // trigger.
258+ constexpr bool __has_format_function = requires (_Formatter& __f, _Tp&& __t , _Context __fc) {
259+ { __f.format (__t , __fc) };
260+ };
261+ constexpr bool __is_format_function_const_qualified = requires (const _Formatter& __cf, _Tp&& __t , _Context __fc) {
262+ { __cf.format (__t , __fc) };
263+ };
264+ constexpr bool __correct_format_function_return_type = requires (_Formatter& __f, _Tp&& __t , _Context __fc) {
265+ { __f.format (__t , __fc)->same_as <typename _Context::iterator> };
266+ };
267+
268+ if constexpr (!__has_format_function)
269+ static_assert (
270+ false , " The required formatter specialization does not have a format function taking the proper arguments." );
271+ else if constexpr (!__is_format_function_const_qualified)
272+ static_assert (false , " The required formatter specialization's format function is not const qualified." );
273+ else if constexpr (!__correct_format_function_return_type)
274+ static_assert (
275+ false , " The required formatter specialization's format function does not return the required type." );
263276
264- else
265- // This should not happen; it makes sure the code is ill-formed.
266- static_assert (false , " The required formatter specialization is not formattable with its context." );
277+ else
278+ // This should not happen; it makes sure the code is ill-formed.
279+ static_assert (false , " The required formatter specialization is not formattable with its context." );
280+ }
267281}
268282
269283// The Psuedo constructor is constrained per [format.arg]/4.
0 commit comments