Skip to content

Commit 23015f6

Browse files
Malevrovichrobot-piglet
authored andcommitted
fix build: make parse constexpr for new fmt
fmt v11+ uses consteval format string validation (fstring) which requires fmt::formatter::parse() to be a constant expression. The non-constexpr parse() methods in protobuf test utils caused compile errors like: error: call to consteval function 'fmt::fstring<...>' is not a constant expression note: non-constexpr function 'parse' cannot be used in a constant expression Make all 4 parse() methods constexpr and simplify them to return ctx.begin(), matching the existing pattern in http_method.hpp and sockaddr.hpp. The removed runtime throw guard is no longer needed — fmt's compile-time checker now catches invalid format specs at compile time with "unknown format specifier" error. --- Pull Request resolved: #1287 commit_hash:bf12ac2b1ab5e631543ee9fc697535c67c4e19fe
1 parent c20e8c8 commit 23015f6

1 file changed

Lines changed: 4 additions & 28 deletions

File tree

libraries/protobuf/tests/json/utils.hpp

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,7 @@ inline const /*deliberately non-constexpr*/ bool
5454

5555
template <>
5656
struct fmt::formatter<USERVER_NAMESPACE::protobuf::json::PrintOptions> {
57-
auto parse(fmt::format_parse_context& ctx) {
58-
auto it = ctx.begin();
59-
if (it != ctx.end() && *it != '}') {
60-
throw fmt::format_error("invalid format");
61-
}
62-
return it;
63-
}
57+
constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
6458

6559
template <typename FormatContext>
6660
auto format(const USERVER_NAMESPACE::protobuf::json::PrintOptions& options, FormatContext& ctx) const
@@ -79,13 +73,7 @@ struct fmt::formatter<USERVER_NAMESPACE::protobuf::json::PrintOptions> {
7973

8074
template <>
8175
struct fmt::formatter<USERVER_NAMESPACE::protobuf::json::ParseOptions> {
82-
auto parse(fmt::format_parse_context& ctx) {
83-
auto it = ctx.begin();
84-
if (it != ctx.end() && *it != '}') {
85-
throw fmt::format_error("invalid format");
86-
}
87-
return it;
88-
}
76+
constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
8977

9078
template <typename FormatContext>
9179
auto format(const USERVER_NAMESPACE::protobuf::json::ParseOptions& options, FormatContext& ctx) const
@@ -101,13 +89,7 @@ struct fmt::formatter<USERVER_NAMESPACE::protobuf::json::ParseOptions> {
10189

10290
template <>
10391
struct fmt::formatter<USERVER_NAMESPACE::protobuf::json::PrintErrorCode> {
104-
auto parse(fmt::format_parse_context& ctx) {
105-
auto it = ctx.begin();
106-
if (it != ctx.end() && *it != '}') {
107-
throw fmt::format_error("invalid format");
108-
}
109-
return it;
110-
}
92+
constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
11193

11294
template <typename FormatContext>
11395
auto format(const USERVER_NAMESPACE::protobuf::json::PrintErrorCode& code, FormatContext& ctx) const
@@ -123,13 +105,7 @@ struct fmt::formatter<USERVER_NAMESPACE::protobuf::json::PrintErrorCode> {
123105

124106
template <>
125107
struct fmt::formatter<USERVER_NAMESPACE::protobuf::json::ParseErrorCode> {
126-
auto parse(fmt::format_parse_context& ctx) {
127-
auto it = ctx.begin();
128-
if (it != ctx.end() && *it != '}') {
129-
throw fmt::format_error("invalid format");
130-
}
131-
return it;
132-
}
108+
constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
133109

134110
template <typename FormatContext>
135111
auto format(const USERVER_NAMESPACE::protobuf::json::ParseErrorCode& code, FormatContext& ctx) const

0 commit comments

Comments
 (0)