When user-defined formatter calls next_arg_id and format-spec is empty we will get compiler error.
Example:
#include <print>
struct FormatNextArg {};
template <> struct std::formatter<FormatNextArg> {
public:
template <class ParseContext> constexpr auto parse(ParseContext &ctx) {
auto it = ctx.begin();
if (it != ctx.end() && *it != '}') {
throw std::format_error{"Expected empty spec"};
}
arg_id = ctx.next_arg_id();
return it;
}
template <class FormatContext>
auto format(FormatNextArg, FormatContext &ctx) const {
return std::format_to(ctx.out(), "arg-id: {}", arg_id);
}
private:
size_t arg_id;
};
int main() {
// std::println("{}, {}", FormatNextArg{}, 0, FormatNextArg{}, "1"); // Does not compile since VS 17.10
std::println("{:}, {:}", FormatNextArg{}, 2, FormatNextArg{}, "3"); // Works, replacement field is not empty
}
Introduced by: #4078
Compiler explorer (VS 17.9): https://godbolt.org/z/rsje4j1hP
When user-defined formatter calls
next_arg_idand format-spec is empty we will get compiler error.Example:
Introduced by: #4078
Compiler explorer (VS 17.9): https://godbolt.org/z/rsje4j1hP