Skip to content

Commit

Permalink
fix parsing in UniqueInstance after supporting incomplete types
Browse files Browse the repository at this point in the history
Summary: The crash message may change subtly after allowing `UniqueInstance` to support incomplete types in: {D55574328}. This causes the `SingletonThreadLocal` tests to fail, noting the difference in crash message between actual and expected. The delta is just extra spaces, so it is fixable.

Reviewed By: Gownta

Differential Revision: D55636182

fbshipit-source-id: d48dfb0bbdf730c6a276ffbe5eaf925ad5e9af6c
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Apr 6, 2024
1 parent 1853475 commit f16c79b
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions folly/detail/UniqueInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,32 @@ bool equal(PtrRange lhs, PtrRange rhs) {
return std::equal(lhs.b, lhs.e, rhs.b, rhs.e, cmp);
}

std::string_view parse_demangled_tag_name(std::string_view str) {
auto off = std::string_view::npos;
// strip surrounding `folly::tag<{...}>`
off = str.find('<');
str = str.substr(off + 1, str.size() - off - 2);
// strip trailing spaces, if any
off = str.find_last_not_of(' ');
str = str.substr(0, off == std::string_view::npos ? off : off + 1);
// done
return str;
}

std::string join(PtrRange types) {
std::ostringstream ret;
for (auto t = types.b; t != types.e; ++t) {
if (t != types.b) {
ret << ", ";
}
auto const str = demangle((*t)->name());
auto const off = str.find('<');
ret << str.substr(off + 1, str.size() - off - 2);
ret << parse_demangled_tag_name(demangle((*t)->name()));
}
return ret.str();
}

template <typename Value>
fbstring render_tmpl(Value value) {
auto const str = demangle(value.tmpl->name());
auto const off = str.find('<');
return str.substr(off + 1, str.size() - off - 2);
return fbstring(parse_demangled_tag_name(demangle(value.tmpl->name())));
}

template <typename Value>
Expand Down

0 comments on commit f16c79b

Please sign in to comment.