Skip to content

Commit

Permalink
Merge pull request #852 from eseiler/fix/cpp23
Browse files Browse the repository at this point in the history
Fix C++23: ~heap_object() with incomplete types
  • Loading branch information
mergify[bot] authored Jul 26, 2024
2 parents 77b3ebd + 80bd587 commit 6416a95
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
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

0 comments on commit 6416a95

Please sign in to comment.