Skip to content

Commit 181996f

Browse files
committed
Fix C++23: ~heap_object() with incomplete types
1 parent 77b3ebd commit 181996f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

schema_salad/cpp_codegen.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ class heap_object {
875875
*data = std::forward<T2>(oth);
876876
}
877877
878-
~heap_object() = default;
878+
~heap_object();
879879
880880
auto operator=(heap_object const& oth) -> heap_object& {
881881
*data = *oth;
@@ -953,6 +953,20 @@ class heap_object {
953953
for key in self.unionDefinitions:
954954
self.unionDefinitions[key].writeDefinition(self.target, " ")
955955

956+
# CPP23: std::unique_ptr in heap_object is constexpr.
957+
# Hence, the compiler will try to instantiate the destructor on definition.
958+
# If the destructor was defined inside heap_object, other classes would only
959+
# be forward declared at this point.
960+
# This results in an error, because the destructor cannot be generated for
961+
# incomplete types.
962+
# Therefore, the destructor is defined here, after all classes have been defined.
963+
self.target.write(
964+
"""template <typename T>
965+
heap_object<T>::~heap_object() = default;
966+
967+
"""
968+
)
969+
956970
# write implementations
957971
for key in self.classDefinitions:
958972
self.classDefinitions[key].writeImplDefinition(self.target, "", " ")

0 commit comments

Comments
 (0)