From 4605cfa30d8b37518f0d6f04fd4f6924c301d596 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 10 Jun 2022 14:20:37 -0700 Subject: [PATCH] Workaround a compilation issue on C++20 Summary: Workaround a compilation issue on C++20 by switching from `fmt::string_view` to `boost::string_view`. A proper fix (https://github.com/fmtlib/fmt/issues/2769) will be backported separately. Differential Revision: D37076763 fbshipit-source-id: d8001bdcd65ee9edf1f265e3aaf281c196e4d155 --- thrift/compiler/generate/t_mstch_cpp2_generator.cc | 2 +- thrift/compiler/generate/t_mstch_py3_generator.cc | 2 +- thrift/compiler/lib/cpp2/util.cc | 8 ++++---- thrift/compiler/lib/cpp2/util.h | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/thrift/compiler/generate/t_mstch_cpp2_generator.cc b/thrift/compiler/generate/t_mstch_cpp2_generator.cc index 3d5694ffc62..32cf30a73c8 100644 --- a/thrift/compiler/generate/t_mstch_cpp2_generator.cc +++ b/thrift/compiler/generate/t_mstch_cpp2_generator.cc @@ -550,7 +550,7 @@ class mstch_cpp2_type : public mstch_type { return resolved_type_->is_string_or_binary() && !is_adapted(); } mstch::node resolved_cpp_type() { - return fmt::to_string(cpp2::get_type(resolved_type_)); + return std::string(cpp2::get_type(resolved_type_)); } mstch::node is_string_or_binary() { return resolved_type_->is_string_or_binary(); diff --git a/thrift/compiler/generate/t_mstch_py3_generator.cc b/thrift/compiler/generate/t_mstch_py3_generator.cc index c0ce4dddd1c..939aac9988d 100644 --- a/thrift/compiler/generate/t_mstch_py3_generator.cc +++ b/thrift/compiler/generate/t_mstch_py3_generator.cc @@ -1377,7 +1377,7 @@ std::shared_ptr type_py3_generator::generate( trueType, mstch_py3_type::CachedProperties{ get_cpp_template(*trueType), - fmt::to_string(cpp2::get_type(trueType)), + std::string(cpp2::get_type(trueType)), {}}); } return std::make_shared( diff --git a/thrift/compiler/lib/cpp2/util.cc b/thrift/compiler/lib/cpp2/util.cc index 30f31587b43..b162e5990a4 100644 --- a/thrift/compiler/lib/cpp2/util.cc +++ b/thrift/compiler/lib/cpp2/util.cc @@ -45,12 +45,12 @@ namespace compiler { namespace cpp2 { namespace { -bool contains(fmt::string_view s, fmt::string_view what) { +bool contains(boost::string_view s, boost::string_view what) { return std::search(s.begin(), s.end(), what.begin(), what.end()) != s.end(); } -fmt::string_view value_or_empty(const std::string* value) { - return value ? *value : std::string_view(""); +boost::string_view value_or_empty(const std::string* value) { + return value ? *value : boost::string_view(""); } int checked_stoi(const std::string& s, std::string msg) { @@ -258,7 +258,7 @@ bool is_orderable(t_type const& type) { return is_orderable(seen, memo, type); } -fmt::string_view get_type(const t_type* type) { +boost::string_view get_type(const t_type* type) { return value_or_empty(gen::cpp::type_resolver::find_type(*type)); } diff --git a/thrift/compiler/lib/cpp2/util.h b/thrift/compiler/lib/cpp2/util.h index 5d90158d58a..9009480cf5b 100644 --- a/thrift/compiler/lib/cpp2/util.h +++ b/thrift/compiler/lib/cpp2/util.h @@ -34,7 +34,7 @@ #include #include -#include +#include namespace apache { namespace thrift { @@ -101,7 +101,7 @@ bool is_orderable(t_type const& type); * Return the cpp.type/cpp2.type attribute or empty string if nothing set. */ // TODO(afuller): Replace with type_resolver::get_type_name. -fmt::string_view get_type(const t_type* type); +boost::string_view get_type(const t_type* type); /** * If the cpp_type is std::unique_ptr the C++ compiler implicitly