Skip to content

Commit c70e03c

Browse files
yuxuanchen1997facebook-github-bot
authored andcommitted
Move destructor to the end of the file to make types complete when instantiating vector
Summary: We are trying to port thrift to build on libc++. libc++'s vector is stricter such that it requires the type argument to be a complete type when its destructor is referenced. This can usually be solved by outlining the destructor to later in the file, which is what we have done here. Reviewed By: iahs Differential Revision: D71133898 fbshipit-source-id: 2f2c9fc41279e17991224c942bdfe348e3940d00
1 parent 68598cd commit c70e03c

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

thrift/lib/cpp2/schema/SyntaxGraph.h

+25-4
Original file line numberDiff line numberDiff line change
@@ -980,15 +980,25 @@ class RpcInterfaceNode : detail::WithDefinition, detail::WithUri {
980980
using detail::WithUri::uri;
981981
folly::span<const FunctionNode> functions() const { return functions_; }
982982

983+
// We outline this destructor because `FunctionNode` is incomplete at the
984+
// time of declaration.
985+
// https://eel.is/c++draft/vector#overview-4 states that the type must be
986+
// complete when any of vector's members are referenced.
987+
~RpcInterfaceNode();
988+
989+
// We need to explicitly declare a default move constructor here because
990+
// https://eel.is/c++draft/class.copy.ctor#8.4 states that the move
991+
// constructor is implicitly declared as defaulted only if there's no user
992+
// declared destructor, even if we default the destructor later.
993+
RpcInterfaceNode(RpcInterfaceNode&&) = default;
994+
RpcInterfaceNode& operator=(RpcInterfaceNode&&) = default;
995+
983996
protected:
984997
RpcInterfaceNode(
985998
const detail::Resolver& resolver,
986999
const apache::thrift::type::DefinitionKey& definitionKey,
9871000
std::string_view uri,
988-
std::vector<FunctionNode>&& functions)
989-
: detail::WithDefinition(resolver, definitionKey),
990-
detail::WithUri(uri),
991-
functions_(std::move(functions)) {}
1001+
std::vector<FunctionNode>&& functions);
9921002

9931003
using detail::WithDefinition::WithResolver::resolver;
9941004

@@ -1486,6 +1496,17 @@ class SyntaxGraph final {
14861496
static_assert(std::is_move_constructible_v<SyntaxGraph>);
14871497
static_assert(std::is_move_assignable_v<SyntaxGraph>);
14881498

1499+
inline RpcInterfaceNode::RpcInterfaceNode(
1500+
const detail::Resolver& resolver,
1501+
const apache::thrift::type::DefinitionKey& definitionKey,
1502+
std::string_view uri,
1503+
std::vector<FunctionNode>&& functions)
1504+
: detail::WithDefinition(resolver, definitionKey),
1505+
detail::WithUri(uri),
1506+
functions_(std::move(functions)) {}
1507+
1508+
inline RpcInterfaceNode::~RpcInterfaceNode() = default;
1509+
14891510
namespace detail {
14901511
template <typename T>
14911512
const T& Lazy<T>::operator*() const {

0 commit comments

Comments
 (0)