Skip to content

Commit 6c47c69

Browse files
committed
mpgen: Work around c++20 / capnproto 0.8 incompatibility
The kj/string.h header installed by capnproto 0.8 doesn't work well when compiling with -std=c++20 or later because the reverse StringPtr/char* comparison function it provides is broken in c++20: inline bool operator==(const char* a, const StringPtr& b) { return b == a; } Before C++20 this would implicitly convert `a` to a StringPtr and call the StringPtr::operator== method. But starting with C++20 it actually calls itself recursively and either loops forever or crashes. This problem was fixed upstream by capnproto/capnproto#1170 in Cap'n Proto 0.9.0. Avoid the problem here for older versions by just not using the operator. A CI job testing older versions is added in the next commit to avoid similar breakage in the future.
1 parent b4120d3 commit 6c47c69

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/mp/gen.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static void Generate(kj::StringPtr src_prefix,
146146
const std::vector<kj::Own<const kj::ReadableDirectory>>& import_dirs)
147147
{
148148
std::string output_path;
149-
if (src_prefix == ".") {
149+
if (src_prefix == kj::StringPtr{"."}) {
150150
output_path = src_file;
151151
} else if (!src_file.startsWith(src_prefix) || src_file.size() <= src_prefix.size() ||
152152
src_file[src_prefix.size()] != '/') {
@@ -156,7 +156,7 @@ static void Generate(kj::StringPtr src_prefix,
156156
}
157157

158158
std::string include_path;
159-
if (include_prefix == ".") {
159+
if (include_prefix == kj::StringPtr{"."}) {
160160
include_path = src_file;
161161
} else if (!src_file.startsWith(include_prefix) || src_file.size() <= include_prefix.size() ||
162162
src_file[include_prefix.size()] != '/') {
@@ -425,8 +425,8 @@ static void Generate(kj::StringPtr src_prefix,
425425

426426
const std::string method_prefix = Format() << message_namespace << "::" << method_interface.getShortDisplayName()
427427
<< "::" << Cap(method_name);
428-
const bool is_construct = method_name == "construct";
429-
const bool is_destroy = method_name == "destroy";
428+
const bool is_construct = method_name == kj::StringPtr{"construct"};
429+
const bool is_destroy = method_name == kj::StringPtr{"destroy"};
430430

431431
struct Field
432432
{
@@ -465,7 +465,7 @@ static void Generate(kj::StringPtr src_prefix,
465465
field.result_is_set = true;
466466
}
467467

468-
if (!param && field_name == "result") {
468+
if (!param && field_name == kj::StringPtr{"result"}) {
469469
field.retval = true;
470470
has_result = true;
471471
}

0 commit comments

Comments
 (0)