Skip to content

Commit

Permalink
Fix C++23: ~heap_object() with incomplete types
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Jul 26, 2024
1 parent 77b3ebd commit 377f6da
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion schema_salad/cpp_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ class heap_object {
*data = std::forward<T2>(oth);
}
~heap_object() = default;
~heap_object();
auto operator=(heap_object const& oth) -> heap_object& {
*data = *oth;
Expand Down Expand Up @@ -953,6 +953,18 @@ class heap_object {
for key in self.unionDefinitions:
self.unionDefinitions[key].writeDefinition(self.target, " ")

# CPP23: std::unique_ptr in heap_object is constexpr.
# Hence, the compiler will try to instantiate the destructor on definition.
# If the destructor was defined inside heap_object, other classes would only be forward declared at this point.
# This results in an error, because the destructor cannot be generated for incomplete types.
# Therefore, the destructor is defined here, after all classes have been defined.
self.target.write(
"""template <typename T>
heap_object<T>::~heap_object() = default;
"""
)

# write implementations
for key in self.classDefinitions:
self.classDefinitions[key].writeImplDefinition(self.target, "", " ")
Expand Down

0 comments on commit 377f6da

Please sign in to comment.