Skip to content

Default-define out-of-line dtors for types with fwd-declared unique_ptr members #1088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 22, 2024
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
6 changes: 6 additions & 0 deletions .github/workflows/build-cppfront.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
- runs-on: macos-latest
compiler: clang++
cxx-std: 'c++20'
- runs-on: ubuntu-22.04
compiler: clang++-15
cxx-std: 'c++20'
- runs-on: ubuntu-24.04
compiler: clang++-16
cxx-std: 'c++20'
Expand All @@ -47,6 +50,9 @@ jobs:
- runs-on: ubuntu-24.04
compiler: clang++-18
cxx-std: 'c++20'
- runs-on: ubuntu-24.04
compiler: clang++-18
cxx-std: 'c++2b'
- runs-on: ubuntu-24.04
compiler: g++-14
cxx-std: 'c++2b'
Expand Down
59 changes: 59 additions & 0 deletions source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ struct primary_expression_node
// Cache to work around <https://github.com/llvm/llvm-project/issues/73336>.
bool expression_list_is_fold_expression = false;

// Out-of-line definition of the dtor is necessary due to the forward-declared
// type(s) used in a std::unique_ptr as a member
~primary_expression_node();

// API
//
Expand Down Expand Up @@ -234,6 +237,10 @@ struct prefix_expression_node
std::vector<token const*> ops;
std::unique_ptr<postfix_expression_node> expr;

// Out-of-line definition of the dtor is necessary due to the forward-declared
// type(s) used in a std::unique_ptr as a member
~prefix_expression_node();

// API
//
auto is_fold_expression() const
Expand Down Expand Up @@ -293,6 +300,10 @@ struct binary_expression_node

binary_expression_node();

// Out-of-line definition of the dtor is necessary due to the forward-declared
// type(s) used as Term in a std::unique_ptr as a member
~binary_expression_node();

struct term
{
token const* op;
Expand Down Expand Up @@ -1087,6 +1098,18 @@ struct template_argument
std::unique_ptr<type_id_node>
> arg;

// The type needs to be movable
// The copy ctor+operator are implicitly deleted due to the std::unique_ptr member
// Because a forward-declared type is used in a std::unique_ptr as a member an out-of-line dtor is necessary
// Because of the OOL dtor together with the fact that the copy ctor+operator are deleted
// the move ctor+operator need to be explicitly defaulted
// As a result the default constructor also needs to be explicitly defaulted
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting side-effect of the changes.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good old SMF defaults 😁 Thanks!

template_argument() = default;
template_argument(template_argument&&) = default;
template_argument& operator=(template_argument&&) = default;

~template_argument();

auto to_string() const
-> std::string;
};
Expand Down Expand Up @@ -1800,6 +1823,10 @@ struct iteration_statement_node
std::unique_ptr<statement_node> body; // used for "for", else null
bool for_with_in = false;// used for "for," says whether loop variable is 'in'

// Out-of-line definition of the dtor is necessary due to the forward-declared
// type(s) used in a std::unique_ptr as a member
~iteration_statement_node();

auto position() const
-> source_position
{
Expand Down Expand Up @@ -1851,6 +1878,10 @@ struct alternative_node
source_position equal_sign;
std::unique_ptr<statement_node> statement;

// Out-of-line definition of the dtor is necessary due to the forward-declared
// type(s) used in a std::unique_ptr as a member
~alternative_node();

auto position() const
-> source_position
{
Expand All @@ -1874,6 +1905,10 @@ struct inspect_expression_node

std::vector<std::unique_ptr<alternative_node>> alternatives;

// Out-of-line definition of the dtor is necessary due to the forward-declared
// type(s) used in a std::unique_ptr as a member
~inspect_expression_node();

auto position() const
-> source_position
{
Expand Down Expand Up @@ -2011,6 +2046,10 @@ struct statement_node

statement_node(compound_statement_node* compound_parent_ = nullptr);

// Out-of-line definition of the dtor is necessary due to the forward-declared
// type(s) used in a std::unique_ptr as a member
~statement_node();

enum active { expression=0, compound, selection, declaration, return_, iteration, using_, contract, inspect, jump };
std::variant<
std::unique_ptr<expression_statement_node>,
Expand Down Expand Up @@ -4386,6 +4425,26 @@ struct translation_unit_node
}
};

// Definitions of out-of-line dtors for nodes with unique_ptr members of forward-declared types
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've decided to add the deferred dtor definitions here, at the point where (to the best of my knowledge) all node types are already defined.

primary_expression_node::~primary_expression_node() = default;

prefix_expression_node::~prefix_expression_node() = default;

template<
String Name,
typename Term
>
binary_expression_node<Name, Term>::~binary_expression_node() = default;

alternative_node::~alternative_node() = default;

iteration_statement_node::~iteration_statement_node() = default;

template_argument::~template_argument() = default;

inspect_expression_node::~inspect_expression_node() = default;

statement_node::~statement_node() = default;

//-----------------------------------------------------------------------
//
Expand Down
Loading