Skip to content

Commit d6b4c2c

Browse files
committed
Add implicit noexcept for destructors too
1 parent ebe5ebc commit d6b4c2c

13 files changed

+41
-83
lines changed

regression-tests/test-results/pure2-types-basics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class myclass {
5050

5151

5252
#line 38 "pure2-types-basics.cpp2"
53-
public: ~myclass();
53+
public: ~myclass() noexcept;
5454

5555

5656
#line 42 "pure2-types-basics.cpp2"
@@ -161,7 +161,7 @@ namespace N {
161161
std::cout << " data: " + cpp2::to_string(data) + ", more: " + cpp2::to_string(more) + "\n";
162162
}
163163

164-
myclass::~myclass(){
164+
myclass::~myclass() noexcept{
165165
std::cout << "myclass: destructor\n";
166166
}
167167

regression-tests/test-results/pure2-types-inheritance.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Cyborg;
2929
class Human {
3030
public: virtual auto speak() const -> void = 0;
3131

32-
public: virtual ~Human();
32+
public: virtual ~Human() noexcept;
3333

3434
public: Human() = default;
3535
public: Human(Human const&) = delete; /* No 'that' constructor, suppress copy */
@@ -42,7 +42,7 @@ namespace N {
4242
public: explicit Machine(cpp2::in<std::string> id);
4343
public: virtual auto work() const -> void = 0;
4444

45-
public: virtual ~Machine();
45+
public: virtual ~Machine() noexcept;
4646

4747
public: Machine(Machine const&) = delete; /* No 'that' constructor, suppress copy */
4848
public: auto operator=(Machine const&) -> void = delete;
@@ -70,7 +70,7 @@ class Cyborg: public Cyborg_name_as_base, public Human, public Cyborg_address_as
7070
public: auto print() const -> void;
7171

7272

73-
public: ~Cyborg();
73+
public: ~Cyborg() noexcept;
7474

7575
public: Cyborg(Cyborg const&) = delete; /* No 'that' constructor, suppress copy */
7676
public: auto operator=(Cyborg const&) -> void = delete;
@@ -93,13 +93,13 @@ auto main() -> int;
9393

9494

9595

96-
Human::~Human(){}
96+
Human::~Human() noexcept{}
9797
#line 6 "pure2-types-inheritance.cpp2"
9898
namespace N {
9999

100100
template <int I> Machine<I>::Machine(cpp2::in<std::string> id){}
101101

102-
template <int I> Machine<I>::~Machine(){}
102+
template <int I> Machine<I>::~Machine() noexcept{}
103103

104104
#line 11 "pure2-types-inheritance.cpp2"
105105
}
@@ -126,7 +126,7 @@ namespace N {
126126
auto Cyborg::print() const -> void {
127127
std::cout << "printing: " + cpp2::to_string(name) + " lives at " + cpp2::to_string(address) + "\n"; }
128128

129-
Cyborg::~Cyborg() {
129+
Cyborg::~Cyborg() noexcept {
130130
std::cout << "Tired but satisfied after another successful day, " + cpp2::to_string(name) + " checks out and goes home to their family\n"; }
131131

132132
#line 38 "pure2-types-inheritance.cpp2"

regression-tests/test-results/pure2-types-smf-and-that-1-provide-everything.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,15 @@ class myclass {
2121

2222

2323
#line 8 "pure2-types-smf-and-that-1-provide-everything.cpp2"
24-
public: myclass(myclass&& that) noexcept
25-
#line 8 "pure2-types-smf-and-that-1-provide-everything.cpp2"
26-
;
24+
public: myclass(myclass&& that) noexcept;
2725

2826

2927
#line 13 "pure2-types-smf-and-that-1-provide-everything.cpp2"
3028
public: auto operator=(myclass const& that) -> myclass& ;
3129

3230

3331
#line 18 "pure2-types-smf-and-that-1-provide-everything.cpp2"
34-
public: auto operator=(myclass&& that) noexcept
35-
#line 18 "pure2-types-smf-and-that-1-provide-everything.cpp2"
36-
-> myclass& ;
32+
public: auto operator=(myclass&& that) noexcept -> myclass& ;
3733

3834

3935
#line 22 "pure2-types-smf-and-that-1-provide-everything.cpp2"
@@ -72,8 +68,6 @@ auto main() -> int;
7268
}
7369

7470
myclass::myclass(myclass&& that) noexcept
75-
#line 8 "pure2-types-smf-and-that-1-provide-everything.cpp2"
76-
7771
: name{ std::move(that).name + "(CM)" }
7872
, addr{ std::move(that).addr }
7973
#line 8 "pure2-types-smf-and-that-1-provide-everything.cpp2"
@@ -92,9 +86,7 @@ auto main() -> int;
9286
#line 16 "pure2-types-smf-and-that-1-provide-everything.cpp2"
9387
}
9488

95-
auto myclass::operator=(myclass&& that) noexcept
96-
#line 18 "pure2-types-smf-and-that-1-provide-everything.cpp2"
97-
-> myclass& {
89+
auto myclass::operator=(myclass&& that) noexcept -> myclass& {
9890
name = std::move(that).name;
9991
addr = std::move(that).addr;
10092
#line 19 "pure2-types-smf-and-that-1-provide-everything.cpp2"

regression-tests/test-results/pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,14 @@ class myclass {
2121

2222

2323
#line 8 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
24-
public: myclass(myclass&& that) noexcept
25-
#line 8 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
26-
;
24+
public: myclass(myclass&& that) noexcept;
2725

2826

2927
#line 13 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
3028
public: auto operator=(myclass const& that) -> myclass& ;
3129

3230
#line 13 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
33-
public: auto operator=(myclass&& that) noexcept
34-
#line 13 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
35-
-> myclass& ;
31+
public: auto operator=(myclass&& that) noexcept -> myclass& ;
3632

3733

3834
#line 18 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
@@ -75,8 +71,6 @@ auto main() -> int;
7571
}
7672

7773
myclass::myclass(myclass&& that) noexcept
78-
#line 8 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
79-
8074
: name{ std::move(that).name + "(CM)" }
8175
, addr{ std::move(that).addr }
8276
#line 8 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
@@ -95,9 +89,7 @@ auto main() -> int;
9589
#line 16 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
9690
}
9791
#line 13 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
98-
auto myclass::operator=(myclass&& that) noexcept
99-
#line 13 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
100-
-> myclass& {
92+
auto myclass::operator=(myclass&& that) noexcept -> myclass& {
10193
name = std::move(that).name;
10294
addr = std::move(that).addr + "(AC)";
10395

regression-tests/test-results/pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ class myclass {
2424

2525

2626
#line 8 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
27-
public: myclass(myclass&& that) noexcept
28-
#line 8 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
29-
;
27+
public: myclass(myclass&& that) noexcept;
3028

3129

3230
#line 13 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
@@ -35,9 +33,7 @@ class myclass {
3533
// std::cout << "assign - copy ";
3634
// }
3735

38-
public: auto operator=(myclass&& that) noexcept
39-
#line 18 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
40-
-> myclass& ;
36+
public: auto operator=(myclass&& that) noexcept -> myclass& ;
4137

4238

4339
#line 22 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
@@ -85,8 +81,6 @@ auto main() -> int;
8581
}
8682

8783
myclass::myclass(myclass&& that) noexcept
88-
#line 8 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
89-
9084
: name{ std::move(that).name + "(CM)" }
9185
, addr{ std::move(that).addr }
9286
#line 8 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
@@ -96,9 +90,7 @@ auto main() -> int;
9690
}
9791

9892
#line 18 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
99-
auto myclass::operator=(myclass&& that) noexcept
100-
#line 18 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
101-
-> myclass& {
93+
auto myclass::operator=(myclass&& that) noexcept -> myclass& {
10294
name = std::move(that).name;
10395
addr = std::move(that).addr;
10496
#line 19 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"

regression-tests/test-results/pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ class myclass {
2020
public: myclass(myclass const& that);
2121

2222
#line 4 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
23-
public: myclass(myclass&& that) noexcept
24-
#line 4 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
25-
;
23+
public: myclass(myclass&& that) noexcept;
2624

2725

2826
#line 8 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
@@ -35,9 +33,7 @@ class myclass {
3533

3634

3735
#line 18 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
38-
public: auto operator=(myclass&& that) noexcept
39-
#line 18 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
40-
-> myclass& ;
36+
public: auto operator=(myclass&& that) noexcept -> myclass& ;
4137

4238

4339
#line 22 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
@@ -76,8 +72,6 @@ auto main() -> int;
7672
}
7773
#line 4 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
7874
myclass::myclass(myclass&& that) noexcept
79-
#line 4 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
80-
8175
: name{ std::move(that).name }
8276
, addr{ std::move(that).addr }
8377
#line 4 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
@@ -96,9 +90,7 @@ auto main() -> int;
9690
#line 16 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
9791
}
9892

99-
auto myclass::operator=(myclass&& that) noexcept
100-
#line 18 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
101-
-> myclass& {
93+
auto myclass::operator=(myclass&& that) noexcept -> myclass& {
10294
name = std::move(that).name;
10395
addr = std::move(that).addr;
10496
#line 19 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"

regression-tests/test-results/pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ class myclass {
2323
public: auto operator=(myclass const& that) -> myclass& ;
2424

2525
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
26-
public: myclass(myclass&& that) noexcept
27-
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
28-
;
26+
public: myclass(myclass&& that) noexcept;
2927

3028
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
31-
public: auto operator=(myclass&& that) noexcept
32-
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
33-
-> myclass& ;
29+
public: auto operator=(myclass&& that) noexcept -> myclass& ;
3430

3531

3632
#line 8 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
@@ -92,18 +88,14 @@ auto main() -> int;
9288
}
9389
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
9490
myclass::myclass(myclass&& that) noexcept
95-
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
96-
9791
: name{ std::move(that).name }
9892
, addr{ std::move(that).addr }
9993
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
10094
{
10195
std::cout << "ctor - copy (GENERAL)";
10296
}
10397
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
104-
auto myclass::operator=(myclass&& that) noexcept
105-
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
106-
-> myclass& {
98+
auto myclass::operator=(myclass&& that) noexcept -> myclass& {
10799
name = std::move(that).name;
108100
addr = std::move(that).addr;
109101
#line 5 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"

regression-tests/test-results/pure2-types-that-parameters.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@ class myclass {
2626

2727

2828
#line 11 "pure2-types-that-parameters.cpp2"
29-
public: myclass(myclass&& that) noexcept
30-
#line 11 "pure2-types-that-parameters.cpp2"
31-
;
29+
public: myclass(myclass&& that) noexcept;
3230

3331
#line 11 "pure2-types-that-parameters.cpp2"
34-
public: auto operator=(myclass&& that) noexcept
35-
#line 11 "pure2-types-that-parameters.cpp2"
36-
-> myclass& ;
32+
public: auto operator=(myclass&& that) noexcept -> myclass& ;
3733

3834

3935
#line 16 "pure2-types-that-parameters.cpp2"
@@ -73,8 +69,6 @@ auto main() -> int;
7369
}
7470

7571
myclass::myclass(myclass&& that) noexcept
76-
#line 11 "pure2-types-that-parameters.cpp2"
77-
7872
: name{ std::move(that).name }
7973
, addr{ std::move(that).addr }
8074
#line 11 "pure2-types-that-parameters.cpp2"
@@ -83,9 +77,7 @@ auto main() -> int;
8377
#line 14 "pure2-types-that-parameters.cpp2"
8478
}
8579
#line 11 "pure2-types-that-parameters.cpp2"
86-
auto myclass::operator=(myclass&& that) noexcept
87-
#line 11 "pure2-types-that-parameters.cpp2"
88-
-> myclass& {
80+
auto myclass::operator=(myclass&& that) noexcept -> myclass& {
8981
name = std::move(that).name;
9082
addr = std::move(that).addr;
9183
return *this;

regression-tests/test-results/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cppfront compiler v0.2.1 Build 8515:1945
2+
cppfront compiler v0.2.1 Build 8520:0928
33
Copyright(c) Herb Sutter All rights reserved
44

55
SPDX-License-Identifier: CC-BY-NC-ND-4.0

source/build.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"8515:1945"
1+
"8520:0928"

source/cppfront.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4131,10 +4131,11 @@ class cppfront
41314131
emit(*n.parameters);
41324132
}
41334133

4134-
// For now, adding implicit noexcept only for move and swap functions
4134+
// For now, adding implicit noexcept only for move/swap/dtor functions
41354135
if (
41364136
n.is_move()
41374137
|| n.is_swap()
4138+
|| n.is_destructor()
41384139
|| generating_move_from == n.my_decl
41394140
)
41404141
{

source/parse.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5713,8 +5713,13 @@ class parser
57135713
&& curr() == "throws"
57145714
)
57155715
{
5716-
if (n->is_move() || n->is_swap()) {
5717-
error( "(experimental restriction) Cpp2 currently does not allow a move or swap function to be designated 'throws'" );
5716+
if (
5717+
n->is_move()
5718+
|| n->is_swap()
5719+
|| n->is_destructor()
5720+
)
5721+
{
5722+
error( "(experimental restriction) Cpp2 currently does not allow a move, swap, or destructor function to be designated 'throws'" );
57185723
return {};
57195724
}
57205725

source/reflect.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class declaration_base
199199
#line 166 "reflect.h2"
200200
public: [[nodiscard]] auto position() const -> source_position override;
201201

202-
public: virtual ~declaration_base();
202+
public: virtual ~declaration_base() noexcept;
203203
public: declaration_base(declaration_base const& that);
204204
#line 167 "reflect.h2"
205205
};
@@ -255,7 +255,7 @@ class declaration
255255
public: [[nodiscard]] auto parent_is_alias() const -> bool;
256256
public: [[nodiscard]] auto parent_is_polymorphic() const -> bool;
257257

258-
public: virtual ~declaration();
258+
public: virtual ~declaration() noexcept;
259259
public: declaration(declaration const& that);
260260
#line 222 "reflect.h2"
261261
};
@@ -661,7 +661,7 @@ namespace meta {
661661

662662
[[nodiscard]] auto declaration_base::position() const -> source_position { return CPP2_UFCS_0(position, (*cpp2::assert_not_null(n))); }
663663

664-
declaration_base::~declaration_base(){}
664+
declaration_base::~declaration_base() noexcept{}
665665
declaration_base::declaration_base(declaration_base const& that)
666666
: compiler_services{ that }
667667
, n{ that.n }{}
@@ -715,7 +715,7 @@ declaration_base::declaration_base(declaration_base const& that)
715715
[[nodiscard]] auto declaration::parent_is_alias() const -> bool { return CPP2_UFCS_0(parent_is_alias, (*cpp2::assert_not_null(n))); }
716716
[[nodiscard]] auto declaration::parent_is_polymorphic() const -> bool { return CPP2_UFCS_0(parent_is_polymorphic, (*cpp2::assert_not_null(n))); }
717717

718-
declaration::~declaration(){}
718+
declaration::~declaration() noexcept{}
719719
declaration::declaration(declaration const& that)
720720
: declaration_base{ that }{}
721721

0 commit comments

Comments
 (0)