Skip to content

Commit 80bd587

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

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
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, "", " ")

schema_salad/tests/cpp_tests/01_single_record.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class heap_object {
200200
*data = std::forward<T2>(oth);
201201
}
202202

203-
~heap_object() = default;
203+
~heap_object();
204204

205205
auto operator=(heap_object const& oth) -> heap_object& {
206206
*data = *oth;
@@ -246,6 +246,9 @@ struct MyRecord {
246246
};
247247
}
248248

249+
template <typename T>
250+
heap_object<T>::~heap_object() = default;
251+
249252
inline auto https___example_com_::MyRecord::toYaml() const -> YAML::Node {
250253
using ::toYaml;
251254
auto n = YAML::Node{};

schema_salad/tests/cpp_tests/02_two_records.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class heap_object {
200200
*data = std::forward<T2>(oth);
201201
}
202202

203-
~heap_object() = default;
203+
~heap_object();
204204

205205
auto operator=(heap_object const& oth) -> heap_object& {
206206
*data = *oth;
@@ -256,6 +256,9 @@ struct MyRecordTwo {
256256
};
257257
}
258258

259+
template <typename T>
260+
heap_object<T>::~heap_object() = default;
261+
259262
inline auto https___example_com_::MyRecordOne::toYaml() const -> YAML::Node {
260263
using ::toYaml;
261264
auto n = YAML::Node{};

schema_salad/tests/cpp_tests/03_simple_inheritance.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class heap_object {
200200
*data = std::forward<T2>(oth);
201201
}
202202

203-
~heap_object() = default;
203+
~heap_object();
204204

205205
auto operator=(heap_object const& oth) -> heap_object& {
206206
*data = *oth;
@@ -257,6 +257,9 @@ struct MyRecordTwo
257257
};
258258
}
259259

260+
template <typename T>
261+
heap_object<T>::~heap_object() = default;
262+
260263
inline auto https___example_com_::MyRecordOne::toYaml() const -> YAML::Node {
261264
using ::toYaml;
262265
auto n = YAML::Node{};

schema_salad/tests/cpp_tests/04_abstract_inheritance.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class heap_object {
200200
*data = std::forward<T2>(oth);
201201
}
202202

203-
~heap_object() = default;
203+
~heap_object();
204204

205205
auto operator=(heap_object const& oth) -> heap_object& {
206206
*data = *oth;
@@ -257,6 +257,9 @@ struct MyRecordTwo
257257
};
258258
}
259259

260+
template <typename T>
261+
heap_object<T>::~heap_object() = default;
262+
260263
inline https___example_com_::MyRecordOne::~MyRecordOne() = default;
261264
inline auto https___example_com_::MyRecordOne::toYaml() const -> YAML::Node {
262265
using ::toYaml;

schema_salad/tests/cpp_tests/05_specialization.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class heap_object {
200200
*data = std::forward<T2>(oth);
201201
}
202202

203-
~heap_object() = default;
203+
~heap_object();
204204

205205
auto operator=(heap_object const& oth) -> heap_object& {
206206
*data = *oth;
@@ -275,6 +275,9 @@ struct MyRecordTwo {
275275
};
276276
}
277277

278+
template <typename T>
279+
heap_object<T>::~heap_object() = default;
280+
278281
inline auto https___example_com_::FieldRecordA::toYaml() const -> YAML::Node {
279282
using ::toYaml;
280283
auto n = YAML::Node{};

0 commit comments

Comments
 (0)