Skip to content

Commit 5ac5df9

Browse files
authored
Default-define out-of-line dtors for types with fwd-declared unique_ptr members (#1088)
* Add OOL dtor defs to fix unique_ptr issues * CI Add Clang 18 with C++23 in build workflow
1 parent e2de0bd commit 5ac5df9

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

.github/workflows/build-cppfront.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ jobs:
3838
- runs-on: macos-latest
3939
compiler: clang++
4040
cxx-std: 'c++20'
41+
- runs-on: ubuntu-22.04
42+
compiler: clang++-15
43+
cxx-std: 'c++20'
4144
- runs-on: ubuntu-24.04
4245
compiler: clang++-16
4346
cxx-std: 'c++20'
@@ -47,6 +50,9 @@ jobs:
4750
- runs-on: ubuntu-24.04
4851
compiler: clang++-18
4952
cxx-std: 'c++20'
53+
- runs-on: ubuntu-24.04
54+
compiler: clang++-18
55+
cxx-std: 'c++2b'
5056
- runs-on: ubuntu-24.04
5157
compiler: g++-14
5258
cxx-std: 'c++2b'

source/parse.h

+59
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ struct primary_expression_node
141141
// Cache to work around <https://github.com/llvm/llvm-project/issues/73336>.
142142
bool expression_list_is_fold_expression = false;
143143

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

145148
// API
146149
//
@@ -234,6 +237,10 @@ struct prefix_expression_node
234237
std::vector<token const*> ops;
235238
std::unique_ptr<postfix_expression_node> expr;
236239

240+
// Out-of-line definition of the dtor is necessary due to the forward-declared
241+
// type(s) used in a std::unique_ptr as a member
242+
~prefix_expression_node();
243+
237244
// API
238245
//
239246
auto is_fold_expression() const
@@ -293,6 +300,10 @@ struct binary_expression_node
293300

294301
binary_expression_node();
295302

303+
// Out-of-line definition of the dtor is necessary due to the forward-declared
304+
// type(s) used as Term in a std::unique_ptr as a member
305+
~binary_expression_node();
306+
296307
struct term
297308
{
298309
token const* op;
@@ -1087,6 +1098,18 @@ struct template_argument
10871098
std::unique_ptr<type_id_node>
10881099
> arg;
10891100

1101+
// The type needs to be movable
1102+
// The copy ctor+operator are implicitly deleted due to the std::unique_ptr member
1103+
// Because a forward-declared type is used in a std::unique_ptr as a member an out-of-line dtor is necessary
1104+
// Because of the OOL dtor together with the fact that the copy ctor+operator are deleted
1105+
// the move ctor+operator need to be explicitly defaulted
1106+
// As a result the default constructor also needs to be explicitly defaulted
1107+
template_argument() = default;
1108+
template_argument(template_argument&&) = default;
1109+
template_argument& operator=(template_argument&&) = default;
1110+
1111+
~template_argument();
1112+
10901113
auto to_string() const
10911114
-> std::string;
10921115
};
@@ -1800,6 +1823,10 @@ struct iteration_statement_node
18001823
std::unique_ptr<statement_node> body; // used for "for", else null
18011824
bool for_with_in = false;// used for "for," says whether loop variable is 'in'
18021825

1826+
// Out-of-line definition of the dtor is necessary due to the forward-declared
1827+
// type(s) used in a std::unique_ptr as a member
1828+
~iteration_statement_node();
1829+
18031830
auto position() const
18041831
-> source_position
18051832
{
@@ -1851,6 +1878,10 @@ struct alternative_node
18511878
source_position equal_sign;
18521879
std::unique_ptr<statement_node> statement;
18531880

1881+
// Out-of-line definition of the dtor is necessary due to the forward-declared
1882+
// type(s) used in a std::unique_ptr as a member
1883+
~alternative_node();
1884+
18541885
auto position() const
18551886
-> source_position
18561887
{
@@ -1874,6 +1905,10 @@ struct inspect_expression_node
18741905

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

1908+
// Out-of-line definition of the dtor is necessary due to the forward-declared
1909+
// type(s) used in a std::unique_ptr as a member
1910+
~inspect_expression_node();
1911+
18771912
auto position() const
18781913
-> source_position
18791914
{
@@ -2011,6 +2046,10 @@ struct statement_node
20112046

20122047
statement_node(compound_statement_node* compound_parent_ = nullptr);
20132048

2049+
// Out-of-line definition of the dtor is necessary due to the forward-declared
2050+
// type(s) used in a std::unique_ptr as a member
2051+
~statement_node();
2052+
20142053
enum active { expression=0, compound, selection, declaration, return_, iteration, using_, contract, inspect, jump };
20152054
std::variant<
20162055
std::unique_ptr<expression_statement_node>,
@@ -4386,6 +4425,26 @@ struct translation_unit_node
43864425
}
43874426
};
43884427

4428+
// Definitions of out-of-line dtors for nodes with unique_ptr members of forward-declared types
4429+
primary_expression_node::~primary_expression_node() = default;
4430+
4431+
prefix_expression_node::~prefix_expression_node() = default;
4432+
4433+
template<
4434+
String Name,
4435+
typename Term
4436+
>
4437+
binary_expression_node<Name, Term>::~binary_expression_node() = default;
4438+
4439+
alternative_node::~alternative_node() = default;
4440+
4441+
iteration_statement_node::~iteration_statement_node() = default;
4442+
4443+
template_argument::~template_argument() = default;
4444+
4445+
inspect_expression_node::~inspect_expression_node() = default;
4446+
4447+
statement_node::~statement_node() = default;
43894448

43904449
//-----------------------------------------------------------------------
43914450
//

0 commit comments

Comments
 (0)