Skip to content

Commit

Permalink
Merge pull request #1114 from dtolnay/failstring
Browse files Browse the repository at this point in the history
Allow trycatch to call Fail using std::string
  • Loading branch information
dtolnay authored Oct 15, 2022
2 parents 031723f + 6f257d8 commit affcc4e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gen/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ pub(super) fn write(out: &mut OutFile) {
}

if builtin.trycatch {
include.string = true;
out.next_section();
writeln!(out, "class Fail final {{");
writeln!(out, " ::rust::repr::PtrLen &throw$;");
Expand All @@ -264,6 +265,7 @@ pub(super) fn write(out: &mut OutFile) {
" Fail(::rust::repr::PtrLen &throw$) : throw$(throw$) {{}}"
);
writeln!(out, " void operator()(const char *) noexcept;");
writeln!(out, " void operator()(const std::string &) noexcept;");
writeln!(out, "}};");
}

Expand Down
5 changes: 5 additions & 0 deletions src/cxx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,16 @@ class Fail final {
public:
Fail(repr::PtrLen &throw$) : throw$(throw$) {}
void operator()(const char *) noexcept;
void operator()(const std::string &) noexcept;
};

void Fail::operator()(const char *catch$) noexcept {
throw$ = cxxbridge1$exception(catch$, std::strlen(catch$));
}

void Fail::operator()(const std::string &catch$) noexcept {
throw$ = cxxbridge1$exception(catch$.data(), catch$.length());
}
} // namespace detail

} // namespace cxxbridge1
Expand Down

0 comments on commit affcc4e

Please sign in to comment.