Skip to content

Commit ebe5ebc

Browse files
committed
Add implicit noexcept for move and swap functions
1 parent d4647ed commit ebe5ebc

14 files changed

+217
-97
lines changed

regression-tests/test-results/pure2-types-ordering-via-meta-functions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ class mystruct {
7171
public: mystruct(mystruct const& that);
7272

7373
public: auto operator=(mystruct const& that) -> mystruct& ;
74-
public: mystruct(mystruct&& that);
75-
public: auto operator=(mystruct&& that) -> mystruct& ;
74+
public: mystruct(mystruct&& that) noexcept;
75+
public: auto operator=(mystruct&& that) noexcept -> mystruct& ;
7676
public: explicit mystruct();
7777

7878
#line 19 "pure2-types-ordering-via-meta-functions.cpp2"
@@ -129,9 +129,9 @@ auto main() -> int;
129129
auto mystruct::operator=(mystruct const& that) -> mystruct& {
130130
val = that.val;
131131
return *this;}
132-
mystruct::mystruct(mystruct&& that)
132+
mystruct::mystruct(mystruct&& that) noexcept
133133
: val{ std::move(that).val }{}
134-
auto mystruct::operator=(mystruct&& that) -> mystruct& {
134+
auto mystruct::operator=(mystruct&& that) noexcept -> mystruct& {
135135
val = std::move(that).val;
136136
return *this;}
137137
mystruct::mystruct(){}

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

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

2222

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

2628

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

3032

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

3438

3539
#line 22 "pure2-types-smf-and-that-1-provide-everything.cpp2"
@@ -67,7 +71,9 @@ auto main() -> int;
6771
std::cout << "ctor - copy (GENERAL)";
6872
}
6973

70-
myclass::myclass(myclass&& that)
74+
myclass::myclass(myclass&& that) noexcept
75+
#line 8 "pure2-types-smf-and-that-1-provide-everything.cpp2"
76+
7177
: name{ std::move(that).name + "(CM)" }
7278
, addr{ std::move(that).addr }
7379
#line 8 "pure2-types-smf-and-that-1-provide-everything.cpp2"
@@ -86,7 +92,9 @@ auto main() -> int;
8692
#line 16 "pure2-types-smf-and-that-1-provide-everything.cpp2"
8793
}
8894

89-
auto myclass::operator=(myclass&& that) -> myclass& {
95+
auto myclass::operator=(myclass&& that) noexcept
96+
#line 18 "pure2-types-smf-and-that-1-provide-everything.cpp2"
97+
-> myclass& {
9098
name = std::move(that).name;
9199
addr = std::move(that).addr;
92100
#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: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ class myclass {
2121

2222

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

2628

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

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

3337

3438
#line 18 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
@@ -70,7 +74,9 @@ auto main() -> int;
7074
std::cout << "ctor - copy (GENERAL)";
7175
}
7276

73-
myclass::myclass(myclass&& that)
77+
myclass::myclass(myclass&& that) noexcept
78+
#line 8 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
79+
7480
: name{ std::move(that).name + "(CM)" }
7581
, addr{ std::move(that).addr }
7682
#line 8 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
@@ -89,7 +95,9 @@ auto main() -> int;
8995
#line 16 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
9096
}
9197
#line 13 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
92-
auto myclass::operator=(myclass&& that) -> myclass& {
98+
auto myclass::operator=(myclass&& that) noexcept
99+
#line 13 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
100+
-> myclass& {
93101
name = std::move(that).name;
94102
addr = std::move(that).addr + "(AC)";
95103

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

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

2525

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

2931

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

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

3842

3943
#line 22 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
@@ -80,7 +84,9 @@ auto main() -> int;
8084
#line 6 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
8185
}
8286

83-
myclass::myclass(myclass&& that)
87+
myclass::myclass(myclass&& that) noexcept
88+
#line 8 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
89+
8490
: name{ std::move(that).name + "(CM)" }
8591
, addr{ std::move(that).addr }
8692
#line 8 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
@@ -90,7 +96,9 @@ auto main() -> int;
9096
}
9197

9298
#line 18 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
93-
auto myclass::operator=(myclass&& that) -> myclass& {
99+
auto myclass::operator=(myclass&& that) noexcept
100+
#line 18 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
101+
-> myclass& {
94102
name = std::move(that).name;
95103
addr = std::move(that).addr;
96104
#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: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ 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);
23+
public: myclass(myclass&& that) noexcept
24+
#line 4 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
25+
;
2426

2527

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

3436

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

3842

3943
#line 22 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
@@ -71,7 +75,9 @@ auto main() -> int;
7175
std::cout << "ctor - copy (GENERAL)";
7276
}
7377
#line 4 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
74-
myclass::myclass(myclass&& that)
78+
myclass::myclass(myclass&& that) noexcept
79+
#line 4 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
80+
7581
: name{ std::move(that).name }
7682
, addr{ std::move(that).addr }
7783
#line 4 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
@@ -90,7 +96,9 @@ auto main() -> int;
9096
#line 16 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
9197
}
9298

93-
auto myclass::operator=(myclass&& that) -> myclass& {
99+
auto myclass::operator=(myclass&& that) noexcept
100+
#line 18 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
101+
-> myclass& {
94102
name = std::move(that).name;
95103
addr = std::move(that).addr;
96104
#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: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ 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);
26+
public: myclass(myclass&& that) noexcept
27+
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
28+
;
2729

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

3135

3236
#line 8 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
@@ -87,15 +91,19 @@ auto main() -> int;
8791
#line 6 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
8892
}
8993
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
90-
myclass::myclass(myclass&& that)
94+
myclass::myclass(myclass&& that) noexcept
95+
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
96+
9197
: name{ std::move(that).name }
9298
, addr{ std::move(that).addr }
9399
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
94100
{
95101
std::cout << "ctor - copy (GENERAL)";
96102
}
97103
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
98-
auto myclass::operator=(myclass&& that) -> myclass& {
104+
auto myclass::operator=(myclass&& that) noexcept
105+
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
106+
-> myclass& {
99107
name = std::move(that).name;
100108
addr = std::move(that).addr;
101109
#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: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ class myclass {
2626

2727

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

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

3438

3539
#line 16 "pure2-types-that-parameters.cpp2"
@@ -68,7 +72,9 @@ auto main() -> int;
6872
#line 9 "pure2-types-that-parameters.cpp2"
6973
}
7074

71-
myclass::myclass(myclass&& that)
75+
myclass::myclass(myclass&& that) noexcept
76+
#line 11 "pure2-types-that-parameters.cpp2"
77+
7278
: name{ std::move(that).name }
7379
, addr{ std::move(that).addr }
7480
#line 11 "pure2-types-that-parameters.cpp2"
@@ -77,7 +83,9 @@ auto main() -> int;
7783
#line 14 "pure2-types-that-parameters.cpp2"
7884
}
7985
#line 11 "pure2-types-that-parameters.cpp2"
80-
auto myclass::operator=(myclass&& that) -> myclass& {
86+
auto myclass::operator=(myclass&& that) noexcept
87+
#line 11 "pure2-types-that-parameters.cpp2"
88+
-> myclass& {
8189
name = std::move(that).name;
8290
addr = std::move(that).addr;
8391
return *this;

regression-tests/test-results/pure2-types-value-types-via-meta-functions.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class widget {
3232
public: [[nodiscard]] auto operator<=>(widget const& that) const -> std::strong_ordering = default;
3333
public: widget(widget const& that);
3434
public: auto operator=(widget const& that) -> widget& ;
35-
public: widget(widget&& that);
36-
public: auto operator=(widget&& that) -> widget& ;
35+
public: widget(widget&& that) noexcept;
36+
public: auto operator=(widget&& that) noexcept -> widget& ;
3737
public: explicit widget();
3838

3939
#line 5 "pure2-types-value-types-via-meta-functions.cpp2"
@@ -48,8 +48,8 @@ class w_widget {
4848
public: [[nodiscard]] auto operator<=>(w_widget const& that) const -> std::weak_ordering = default;
4949
public: w_widget(w_widget const& that);
5050
public: auto operator=(w_widget const& that) -> w_widget& ;
51-
public: w_widget(w_widget&& that);
52-
public: auto operator=(w_widget&& that) -> w_widget& ;
51+
public: w_widget(w_widget&& that) noexcept;
52+
public: auto operator=(w_widget&& that) noexcept -> w_widget& ;
5353
public: explicit w_widget();
5454

5555
#line 10 "pure2-types-value-types-via-meta-functions.cpp2"
@@ -64,8 +64,8 @@ class p_widget {
6464
public: [[nodiscard]] auto operator<=>(p_widget const& that) const -> std::partial_ordering = default;
6565
public: p_widget(p_widget const& that);
6666
public: auto operator=(p_widget const& that) -> p_widget& ;
67-
public: p_widget(p_widget&& that);
68-
public: auto operator=(p_widget&& that) -> p_widget& ;
67+
public: p_widget(p_widget&& that) noexcept;
68+
public: auto operator=(p_widget&& that) noexcept -> p_widget& ;
6969
public: explicit p_widget();
7070

7171
#line 15 "pure2-types-value-types-via-meta-functions.cpp2"
@@ -100,9 +100,9 @@ template<typename T> auto test() -> void;
100100
auto widget::operator=(widget const& that) -> widget& {
101101
val = that.val;
102102
return *this;}
103-
widget::widget(widget&& that)
103+
widget::widget(widget&& that) noexcept
104104
: val{ std::move(that).val }{}
105-
auto widget::operator=(widget&& that) -> widget& {
105+
auto widget::operator=(widget&& that) noexcept -> widget& {
106106
val = std::move(that).val;
107107
return *this;}
108108
widget::widget(){}
@@ -125,9 +125,9 @@ widget::widget(){}
125125
auto w_widget::operator=(w_widget const& that) -> w_widget& {
126126
val = that.val;
127127
return *this;}
128-
w_widget::w_widget(w_widget&& that)
128+
w_widget::w_widget(w_widget&& that) noexcept
129129
: val{ std::move(that).val }{}
130-
auto w_widget::operator=(w_widget&& that) -> w_widget& {
130+
auto w_widget::operator=(w_widget&& that) noexcept -> w_widget& {
131131
val = std::move(that).val;
132132
return *this;}
133133
w_widget::w_widget(){}
@@ -150,9 +150,9 @@ w_widget::w_widget(){}
150150
auto p_widget::operator=(p_widget const& that) -> p_widget& {
151151
val = that.val;
152152
return *this;}
153-
p_widget::p_widget(p_widget&& that)
153+
p_widget::p_widget(p_widget&& that) noexcept
154154
: val{ std::move(that).val }{}
155-
auto p_widget::operator=(p_widget&& that) -> p_widget& {
155+
auto p_widget::operator=(p_widget&& that) noexcept -> p_widget& {
156156
val = std::move(that).val;
157157
return *this;}
158158
p_widget::p_widget(){}

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:0551
2+
cppfront compiler v0.2.1 Build 8515:1945
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:0551"
1+
"8515:1945"

source/cppfront.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4131,12 +4131,15 @@ class cppfront
41314131
emit(*n.parameters);
41324132
}
41334133

4134-
// Add implicit noexcept when we implement proper EH
4135-
// to handle calling Cpp1 code that throws
4136-
//if (!n.throws) {
4137-
// printer.add_pad_in_this_line(-25);
4138-
// printer.print_cpp2( " noexcept", n.position() );
4139-
//}
4134+
// For now, adding implicit noexcept only for move and swap functions
4135+
if (
4136+
n.is_move()
4137+
|| n.is_swap()
4138+
|| generating_move_from == n.my_decl
4139+
)
4140+
{
4141+
printer.print_cpp2( " noexcept", n.position() );
4142+
}
41404143

41414144
printer.print_cpp2( suffix1, n.position() );
41424145

0 commit comments

Comments
 (0)