-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
bugSomething isn't workingSomething isn't workingfixedSomething works now, yay!Something works now, yay!formatC++20/23 formatC++20/23 format
Description
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
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfixedSomething works now, yay!Something works now, yay!formatC++20/23 formatC++20/23 format