Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 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,20 @@ 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
5 changes: 4 additions & 1 deletion schema_salad/tests/cpp_tests/01_single_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,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 @@ -246,6 +246,9 @@ struct MyRecord {
};
}

template <typename T>
heap_object<T>::~heap_object() = default;

inline auto https___example_com_::MyRecord::toYaml() const -> YAML::Node {
using ::toYaml;
auto n = YAML::Node{};
Expand Down
5 changes: 4 additions & 1 deletion schema_salad/tests/cpp_tests/02_two_records.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,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 @@ -256,6 +256,9 @@ struct MyRecordTwo {
};
}

template <typename T>
heap_object<T>::~heap_object() = default;

inline auto https___example_com_::MyRecordOne::toYaml() const -> YAML::Node {
using ::toYaml;
auto n = YAML::Node{};
Expand Down
5 changes: 4 additions & 1 deletion schema_salad/tests/cpp_tests/03_simple_inheritance.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,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 @@ -257,6 +257,9 @@ struct MyRecordTwo
};
}

template <typename T>
heap_object<T>::~heap_object() = default;

inline auto https___example_com_::MyRecordOne::toYaml() const -> YAML::Node {
using ::toYaml;
auto n = YAML::Node{};
Expand Down
5 changes: 4 additions & 1 deletion schema_salad/tests/cpp_tests/04_abstract_inheritance.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,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 @@ -257,6 +257,9 @@ struct MyRecordTwo
};
}

template <typename T>
heap_object<T>::~heap_object() = default;

inline https___example_com_::MyRecordOne::~MyRecordOne() = default;
inline auto https___example_com_::MyRecordOne::toYaml() const -> YAML::Node {
using ::toYaml;
Expand Down
5 changes: 4 additions & 1 deletion schema_salad/tests/cpp_tests/05_specialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,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 @@ -275,6 +275,9 @@ struct MyRecordTwo {
};
}

template <typename T>
heap_object<T>::~heap_object() = default;

inline auto https___example_com_::FieldRecordA::toYaml() const -> YAML::Node {
using ::toYaml;
auto n = YAML::Node{};
Expand Down
Loading