Skip to content

Commit 5a252cc

Browse files
committed
Emit this functions with ref-qualifiers per #653, closes #651, closes #653
1 parent 1764f0c commit 5a252cc

18 files changed

+229
-218
lines changed

regression-tests/pure2-types-basics.cpp2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ myclass : type = {
3535
std::cout << " data: (data)$, more: (more)$\n";
3636
}
3737

38+
print: (move this) = {
39+
std::cout << " (move print) data: (data)$, more: (more)$\n";
40+
}
41+
3842
operator=: (move this) = {
3943
std::cout << "myclass: destructor\n";
4044
}

regression-tests/test-results/pure2-bugfix-for-discard-precedence.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class quantity {
1919

2020
#line 3 "pure2-bugfix-for-discard-precedence.cpp2"
2121
public: auto operator=(cpp2::in<cpp2::i32> x) -> quantity& ;
22-
public: [[nodiscard]] auto operator+(quantity const& that) -> quantity;
22+
public: [[nodiscard]] auto operator+(quantity const& that) & -> quantity;
2323

2424
public: quantity(quantity const&) = delete; /* No 'that' constructor, suppress copy */
2525
public: auto operator=(quantity const&) -> void = delete;
@@ -43,7 +43,7 @@ auto main(int const argc_, char** argv_) -> int;
4343
return *this;
4444
#line 3 "pure2-bugfix-for-discard-precedence.cpp2"
4545
}
46-
[[nodiscard]] auto quantity::operator+(quantity const& that) -> quantity { return quantity(number + that.number); }
46+
[[nodiscard]] auto quantity::operator+(quantity const& that) & -> quantity { return quantity(number + that.number); }
4747

4848
#line 7 "pure2-bugfix-for-discard-precedence.cpp2"
4949
auto main(int const argc_, char** argv_) -> int{

regression-tests/test-results/pure2-defaulted-comparisons-and-final-types.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class widget final
2323
#line 6 "pure2-defaulted-comparisons-and-final-types.cpp2"
2424
public: auto operator=(cpp2::in<int> value) -> widget& ;
2525

26-
public: [[nodiscard]] auto operator==(widget const& that) const -> bool = default;
26+
public: [[nodiscard]] auto operator==(widget const& that) const& -> bool = default;
2727

28-
public: [[nodiscard]] auto operator<=>(widget const& that) const -> std::strong_ordering = default;
28+
public: [[nodiscard]] auto operator<=>(widget const& that) const& -> std::strong_ordering = default;
2929

3030
public: widget(widget const&) = delete; /* No 'that' constructor, suppress copy */
3131
public: auto operator=(widget const&) -> void = delete;

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace N {
1212

1313
class myclass;
1414

15-
#line 60 "pure2-types-basics.cpp2"
15+
#line 64 "pure2-types-basics.cpp2"
1616
}
1717

1818

@@ -46,18 +46,22 @@ class myclass {
4646

4747

4848
#line 34 "pure2-types-basics.cpp2"
49-
public: auto print() const -> void;
49+
public: auto print() const& -> void;
5050

5151

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

5555

5656
#line 42 "pure2-types-basics.cpp2"
57-
public: auto f(cpp2::in<int> x) const -> void;
57+
public: ~myclass() noexcept;
5858

5959

6060
#line 46 "pure2-types-basics.cpp2"
61+
public: auto f(cpp2::in<int> x) const& -> void;
62+
63+
64+
#line 50 "pure2-types-basics.cpp2"
6165
private: int data {42 * 12};
6266
private: std::string more {std::to_string(42 * 12)};
6367

@@ -68,7 +72,7 @@ class myclass {
6872
public: nested(nested const&) = delete; /* No 'that' constructor, suppress copy */
6973
public: auto operator=(nested const&) -> void = delete;
7074

71-
#line 51 "pure2-types-basics.cpp2"
75+
#line 55 "pure2-types-basics.cpp2"
7276
};
7377

7478
public: template<typename T, typename U> [[nodiscard]] static auto f1(T const& t, U const& u) -> auto;
@@ -78,7 +82,7 @@ class myclass {
7882

7983
public: myclass(myclass const&) = delete; /* No 'that' constructor, suppress copy */
8084
public: auto operator=(myclass const&) -> void = delete;
81-
#line 58 "pure2-types-basics.cpp2"
85+
#line 62 "pure2-types-basics.cpp2"
8286
};
8387

8488
}
@@ -157,28 +161,32 @@ namespace N {
157161
print();
158162
}
159163

160-
auto myclass::print() const -> void{
164+
auto myclass::print() const& -> void{
161165
std::cout << " data: " + cpp2::to_string(data) + ", more: " + cpp2::to_string(more) + "\n";
162166
}
163167

168+
auto myclass::print() && -> void{
169+
std::cout << " (move print) data: " + cpp2::to_string(data) + ", more: " + cpp2::to_string(more) + "\n";
170+
}
171+
164172
myclass::~myclass() noexcept{
165173
std::cout << "myclass: destructor\n";
166174
}
167175

168-
auto myclass::f(cpp2::in<int> x) const -> void{
176+
auto myclass::f(cpp2::in<int> x) const& -> void{
169177
std::cout << "N::myclass::f with " + cpp2::to_string(x) + "\n";
170178
}
171179

172-
#line 50 "pure2-types-basics.cpp2"
180+
#line 54 "pure2-types-basics.cpp2"
173181
auto myclass::nested::g() -> void { std::cout << "N::myclass::nested::g\n"; }
174182

175-
#line 53 "pure2-types-basics.cpp2"
183+
#line 57 "pure2-types-basics.cpp2"
176184
template<typename T, typename U> [[nodiscard]] auto myclass::f1(T const& t, U const& u) -> auto { return t + u; }
177185
template<typename T, typename U> [[nodiscard]] auto myclass::f2(T const& t, U const& u) -> auto { return t + u; }
178186
template<auto T, auto U> [[nodiscard]] auto myclass::f3() -> auto { return T + U; }
179187
template<cpp2::i8 T, cpp2::i16 U> [[nodiscard]] auto myclass::f4() -> auto { return T + U; }
180188

181-
#line 60 "pure2-types-basics.cpp2"
189+
#line 64 "pure2-types-basics.cpp2"
182190
}
183191

184192
auto main() -> int{

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Cyborg;
2727

2828
#line 2 "pure2-types-inheritance.cpp2"
2929
class Human {
30-
public: virtual auto speak() const -> void = 0;
30+
public: virtual auto speak() const& -> void = 0;
3131

3232
public: virtual ~Human() noexcept;
3333

@@ -40,7 +40,7 @@ public: virtual ~Human() noexcept;
4040
namespace N {
4141
template<int I> class Machine {
4242
public: explicit Machine([[maybe_unused]] cpp2::in<std::string> param2);
43-
public: virtual auto work() const -> void = 0;
43+
public: virtual auto work() const& -> void = 0;
4444

4545
public: virtual ~Machine() noexcept;
4646

@@ -61,13 +61,13 @@ class Cyborg: public Cyborg_name_as_base, public Human, public Cyborg_address_as
6161

6262

6363
#line 25 "pure2-types-inheritance.cpp2"
64-
public: auto speak() const -> void override;
64+
public: auto speak() const& -> void override;
6565

6666

67-
public: auto work() const -> void override;
67+
public: auto work() const& -> void override;
6868

6969

70-
public: auto print() const -> void;
70+
public: auto print() const& -> void;
7171

7272

7373
public: ~Cyborg() noexcept;
@@ -117,13 +117,13 @@ namespace N {
117117
std::cout << cpp2::to_string(name) + " checks in for the day's shift\n";
118118
}
119119

120-
auto Cyborg::speak() const -> void {
120+
auto Cyborg::speak() const& -> void {
121121
std::cout << cpp2::to_string(name) + " cracks a few jokes with a coworker\n"; }
122122

123-
auto Cyborg::work() const -> void {
123+
auto Cyborg::work() const& -> void {
124124
std::cout << cpp2::to_string(name) + " carries some half-tonne crates of Fe2O3 to cold storage\n"; }
125125

126-
auto Cyborg::print() const -> void {
126+
auto Cyborg::print() const& -> void {
127127
std::cout << "printing: " + cpp2::to_string(name) + " lives at " + cpp2::to_string(address) + "\n"; }
128128

129129
Cyborg::~Cyborg() noexcept {

regression-tests/test-results/pure2-types-order-independence-and-nesting.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class X {
5151

5252
#line 34 "pure2-types-order-independence-and-nesting.cpp2"
5353
// X::exx member function description here
54-
public: auto exx(cpp2::in<int> count) const -> void;
54+
public: auto exx(cpp2::in<int> count) const& -> void;
5555

5656
public: X(X const&) = delete; /* No 'that' constructor, suppress copy */
5757
public: auto operator=(X const&) -> void = delete;
@@ -69,7 +69,7 @@ class Y {
6969
#line 49 "pure2-types-order-independence-and-nesting.cpp2"
7070
public: auto operator=(X* x) -> Y& ;
7171

72-
public: auto why(cpp2::in<int> count) const -> void;
72+
public: auto why(cpp2::in<int> count) const& -> void;
7373

7474
public: Y(Y const&) = delete; /* No 'that' constructor, suppress copy */
7575
public: auto operator=(Y const&) -> void = delete;
@@ -151,7 +151,7 @@ namespace N {
151151
}
152152

153153
#line 35 "pure2-types-order-independence-and-nesting.cpp2"
154-
auto X::exx(cpp2::in<int> count) const -> void{
154+
auto X::exx(cpp2::in<int> count) const& -> void{
155155
// Exercise '_' anonymous objects too while we're at it
156156
cpp2::finally auto_37_9 {[&]() -> void { std::cout << "leaving call to 'why(" + cpp2::to_string(count) + ")'\n"; }};
157157
if (cpp2::cmp_less(count,5)) {
@@ -171,7 +171,7 @@ namespace N {
171171
#line 49 "pure2-types-order-independence-and-nesting.cpp2"
172172
}
173173

174-
auto Y::why(cpp2::in<int> count) const -> void {
174+
auto Y::why(cpp2::in<int> count) const& -> void {
175175
CPP2_UFCS(exx, (*cpp2::assert_not_null(px)), count + 1); }// use X object from Y
176176

177177
#line 55 "pure2-types-order-independence-and-nesting.cpp2"

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class my_integer {
3333
#line 4 "pure2-types-ordering-via-meta-functions.cpp2"
3434
public: auto operator=(cpp2::in<int> val) -> my_integer& ;
3535

36-
public: [[nodiscard]] auto operator<=>(my_integer const& that) const -> std::strong_ordering = default;
36+
public: [[nodiscard]] auto operator<=>(my_integer const& that) const& -> std::strong_ordering = default;
3737

3838
public: my_integer(my_integer const&) = delete; /* No 'that' constructor, suppress copy */
3939
public: auto operator=(my_integer const&) -> void = delete;
@@ -46,7 +46,7 @@ class case_insensitive_string {
4646
#line 9 "pure2-types-ordering-via-meta-functions.cpp2"
4747
public: auto operator=(cpp2::in<std::string> val) -> case_insensitive_string& ;
4848

49-
public: [[nodiscard]] auto operator<=>(case_insensitive_string const& that) const -> std::weak_ordering = default;
49+
public: [[nodiscard]] auto operator<=>(case_insensitive_string const& that) const& -> std::weak_ordering = default;
5050

5151
public: case_insensitive_string(case_insensitive_string const&) = delete; /* No 'that' constructor, suppress copy */
5252
public: auto operator=(case_insensitive_string const&) -> void = delete;
@@ -59,7 +59,7 @@ class person_in_family_tree {
5959
#line 14 "pure2-types-ordering-via-meta-functions.cpp2"
6060
public: auto operator=(cpp2::in<int> parents) -> person_in_family_tree& ;
6161

62-
public: [[nodiscard]] auto operator<=>(person_in_family_tree const& that) const -> std::partial_ordering = default;
62+
public: [[nodiscard]] auto operator<=>(person_in_family_tree const& that) const& -> std::partial_ordering = default;
6363

6464
public: person_in_family_tree(person_in_family_tree const&) = delete; /* No 'that' constructor, suppress copy */
6565
public: auto operator=(person_in_family_tree const&) -> void = delete;

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

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

4848
cpp2::in<std::string_view> prefix,
4949
cpp2::in<std::string_view> suffix
50-
) const -> void;
50+
) const& -> void;
5151

5252
#line 37 "pure2-types-smf-and-that-1-provide-everything.cpp2"
5353
};
@@ -118,7 +118,7 @@ auto main() -> int;
118118

119119
cpp2::in<std::string_view> prefix,
120120
cpp2::in<std::string_view> suffix
121-
) const -> void {
121+
) const& -> void {
122122
std::cout << prefix << "[ " + cpp2::to_string(name) + " | " + cpp2::to_string(addr) + " ]" << suffix; }
123123

124124
#line 39 "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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class myclass {
5050

5151
cpp2::in<std::string_view> prefix,
5252
cpp2::in<std::string_view> suffix
53-
) const -> void;
53+
) const& -> void;
5454

5555
#line 37 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
5656
};
@@ -123,7 +123,7 @@ auto main() -> int;
123123

124124
cpp2::in<std::string_view> prefix,
125125
cpp2::in<std::string_view> suffix
126-
) const -> void {
126+
) const& -> void {
127127
std::cout << prefix << "[ " + cpp2::to_string(name) + " | " + cpp2::to_string(addr) + " ]" << suffix; }
128128

129129
#line 39 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"

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

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

5252
cpp2::in<std::string_view> prefix,
5353
cpp2::in<std::string_view> suffix
54-
) const -> void;
54+
) const& -> void;
5555

5656
#line 37 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
5757
};
@@ -122,7 +122,7 @@ auto main() -> int;
122122

123123
cpp2::in<std::string_view> prefix,
124124
cpp2::in<std::string_view> suffix
125-
) const -> void {
125+
) const& -> void {
126126
std::cout << prefix << "[ " + cpp2::to_string(name) + " | " + cpp2::to_string(addr) + " ]" << suffix; }
127127

128128
#line 39 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"

0 commit comments

Comments
 (0)