Skip to content

Commit 5dc8beb

Browse files
committed
Fix leftover bugs in previous commit
Updates #1146 and #904 And remove three "temporary alpha limitation" cases
1 parent 116c941 commit 5dc8beb

File tree

8 files changed

+310
-97
lines changed

8 files changed

+310
-97
lines changed

regression-tests/test-results/pure2-bugfix-for-ufcs-arguments.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ class A {
8181
class B {
8282
public: A m;
8383
public: auto f() const& -> void;
84+
public: explicit B(auto const& m_);
85+
86+
public: auto operator=(auto const& m_) -> B& ;
87+
88+
#line 71 "pure2-bugfix-for-ufcs-arguments.cpp2"
8489
};
8590

8691

@@ -167,3 +172,9 @@ namespace ns {
167172
#line 70 "pure2-bugfix-for-ufcs-arguments.cpp2"
168173
auto B::f() const& -> void { CPP2_UFCS(f)(m); }
169174

175+
B::B(auto const& m_)
176+
: m{ m_ }{}
177+
178+
auto B::operator=(auto const& m_) -> B& {
179+
m = m_;
180+
return *this;}

regression-tests/test-results/pure2-last-use.cpp

Lines changed: 111 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,17 +243,36 @@ class issue_857 {
243243
};
244244

245245
class issue_857_2 {
246-
public: std::unique_ptr<int> a; // OK: No error about 'a' being unused.
246+
public: std::unique_ptr<int> a;
247+
public: explicit issue_857_2(auto const& a_);
248+
249+
public: auto operator=(auto const& a_) -> issue_857_2& ;
250+
251+
#line 258 "pure2-last-use.cpp2"
252+
// OK: No error about 'a' being unused.
253+
#line 259 "pure2-last-use.cpp2"
247254
};
248255

249256
extern int gi;
250257
class issue_857_3 {
251258
public: std::add_lvalue_reference_t<int> i {gi};
252259
public: auto f() && -> void;
260+
public: explicit issue_857_3(auto const& i_);
261+
262+
public: auto operator=(auto const& i_) -> issue_857_3& ;
263+
public: explicit issue_857_3();
264+
265+
#line 265 "pure2-last-use.cpp2"
253266
};
254267
class issue_857_6 {
255268
public: auto f() && -> void;
256269
public: std::add_lvalue_reference_t<int> i {gi};
270+
public: explicit issue_857_6(auto const& i_);
271+
272+
public: auto operator=(auto const& i_) -> issue_857_6& ;
273+
public: explicit issue_857_6();
274+
275+
#line 269 "pure2-last-use.cpp2"
257276
};
258277

259278
// TODO Alias `std::move_only_function`.
@@ -270,6 +289,8 @@ class issue_857_4 {
270289
public: std::add_pointer_t<int(int)> g;
271290
public: move_only_function<int()> mf;
272291
public: move_only_function<int(int)> mg;
292+
public: explicit issue_857_4(auto const& f_, auto const& g_, auto const& mf_, auto const& mg_);
293+
273294
// h0: (move this) = _ = mf();
274295
// h1: (move this) = _ = this.mf();
275296
// h2: (move this, that) = _ = that.mf();
@@ -323,11 +344,17 @@ class issue_857_4 {
323344
// /*i3*/ _ = this.mf();
324345
// /*i3*/ }
325346
// }
347+
#line 336 "pure2-last-use.cpp2"
326348
};
327349

328350
class issue_857_5 {
329351
public: auto f() && -> void;
330352
public: std::unique_ptr<int> a;
353+
public: explicit issue_857_5(auto const& a_);
354+
355+
public: auto operator=(auto const& a_) -> issue_857_5& ;
356+
357+
#line 341 "pure2-last-use.cpp2"
331358
};
332359

333360
struct issue_857_7_A_as_base { std::add_lvalue_reference_t<int> A; };
@@ -336,13 +363,19 @@ class issue_857_7: public issue_857_7_A_as_base, public std::monostate {
336363

337364
#line 346 "pure2-last-use.cpp2"
338365
public: auto F() && -> void;
366+
public: explicit issue_857_7(auto const& A_);
367+
368+
#line 347 "pure2-last-use.cpp2"
339369
};
340370

341371
class issue_857_8 {
342372
public: std::unique_ptr<int> a;
343373
public: move_only_function<int()> b;
344374
public: std::add_lvalue_reference_t<int> c;
345375
public: auto d() && -> void;
376+
public: explicit issue_857_8(auto const& a_, auto const& b_, auto const& c_);
377+
378+
#line 354 "pure2-last-use.cpp2"
346379
};
347380
class issue_857_9: public issue_857_8 {
348381

@@ -438,6 +471,9 @@ class cpp2_union {
438471
class my_string {
439472
public: std::string string;
440473
public: std::size_t size {CPP2_UFCS(size)(string)};
474+
public: explicit my_string(auto const& string_, auto const& size_);
475+
476+
#line 855 "pure2-last-use.cpp2"
441477
};
442478

443479
using no_pessimizing_move_ret = std::unique_ptr<int>;
@@ -470,6 +506,9 @@ int inline constexpr x{ 0 };
470506
class t {
471507
public: std::unique_ptr<int> x;
472508
public: auto operator()() && -> void;
509+
public: explicit t(auto const& x_);
510+
511+
public: auto operator=(auto const& x_) -> t& ;
473512

474513
#line 938 "pure2-last-use.cpp2"
475514
};
@@ -484,12 +523,18 @@ auto loops_and_captures() -> void;
484523
#line 984 "pure2-last-use.cpp2"
485524
class types {
486525
public: std::unique_ptr<int> x;
526+
public: explicit types(auto const& x_);
527+
528+
public: auto operator=(auto const& x_) -> types& ;
529+
530+
#line 986 "pure2-last-use.cpp2"
487531
// f: (move this) = _ = :() x$*;
488532
// g: (move this) = {
489533
// for (:() x$*)
490534
// do (_)
491535
// { }
492536
// }
537+
#line 992 "pure2-last-use.cpp2"
493538
};
494539

495540
auto skip_hidden_names() -> void;
@@ -692,14 +737,40 @@ auto issue_850() -> void{
692737
#line 181 "pure2-last-use.cpp2"
693738
auto issue_857::h() & -> void { f_inout(a); }
694739

740+
issue_857_2::issue_857_2(auto const& a_)
741+
: a{ a_ }{}
742+
743+
auto issue_857_2::operator=(auto const& a_) -> issue_857_2& {
744+
a = a_;
745+
return *this;}
695746
#line 261 "pure2-last-use.cpp2"
696747
int gi {0};
697748

698749
#line 264 "pure2-last-use.cpp2"
699-
auto issue_857_3::f() && -> void { f_inout(cpp2::move(*this).i); }// OK: The implicit `this` is moved, not `i`.
750+
auto issue_857_3::f() && -> void { f_inout(cpp2::move(*this).i); }
751+
752+
issue_857_3::issue_857_3(auto const& i_)
753+
: i{ i_ }{}
754+
755+
auto issue_857_3::operator=(auto const& i_) -> issue_857_3& {
756+
i = i_;
757+
return *this;}
758+
issue_857_3::issue_857_3(){}
759+
#line 264 "pure2-last-use.cpp2"
760+
// OK: The implicit `this` is moved, not `i`.
761+
762+
#line 267 "pure2-last-use.cpp2"
763+
auto issue_857_6::f() && -> void { f_inout(cpp2::move(*this).i); }
764+
765+
issue_857_6::issue_857_6(auto const& i_)
766+
: i{ i_ }{}
700767

768+
auto issue_857_6::operator=(auto const& i_) -> issue_857_6& {
769+
i = i_;
770+
return *this;}
771+
issue_857_6::issue_857_6(){}
701772
#line 267 "pure2-last-use.cpp2"
702-
auto issue_857_6::f() && -> void { f_inout(cpp2::move(*this).i); }// OK: The implicit `this` is moved, not `i`.
773+
// OK: The implicit `this` is moved, not `i`.
703774

704775
#line 273 "pure2-last-use.cpp2"
705776
template <typename T> move_only_function<T>::move_only_function(){}
@@ -711,15 +782,36 @@ int gi {0};
711782
#line 275 "pure2-last-use.cpp2"
712783
template <typename T> [[nodiscard]] auto move_only_function<T>::operator()([[maybe_unused]] auto const& ...unnamed_param_2) && -> int { return 0; }
713784

785+
issue_857_4::issue_857_4(auto const& f_, auto const& g_, auto const& mf_, auto const& mg_)
786+
: f{ f_ }
787+
, g{ g_ }
788+
, mf{ mf_ }
789+
, mg{ mg_ }{}
790+
714791
#line 339 "pure2-last-use.cpp2"
715792
auto issue_857_5::f() && -> void { f_copy(std::move(cpp2::move(*this).a)); }
716793

794+
issue_857_5::issue_857_5(auto const& a_)
795+
: a{ a_ }{}
796+
797+
auto issue_857_5::operator=(auto const& a_) -> issue_857_5& {
798+
a = a_;
799+
return *this;}
717800
#line 346 "pure2-last-use.cpp2"
718801
auto issue_857_7::F() && -> void { f_inout(cpp2::move(*this).A); }
719802

803+
issue_857_7::issue_857_7(auto const& A_)
804+
: issue_857_7_A_as_base{ A_ }
805+
, std::monostate{ }{}
806+
720807
#line 353 "pure2-last-use.cpp2"
721808
auto issue_857_8::d() && -> void{}
722809

810+
issue_857_8::issue_857_8(auto const& a_, auto const& b_, auto const& c_)
811+
: a{ a_ }
812+
, b{ b_ }
813+
, c{ c_ }{}
814+
723815
#line 362 "pure2-last-use.cpp2"
724816
auto issue_857_9::f2() && -> void { f_inout(c); }// OK: Happens to work, like non-'move' 'this' parameters.
725817

@@ -1270,6 +1362,10 @@ auto enum_2() -> void{
12701362
static_cast<void>(cpp2::move((*this)));
12711363
}
12721364

1365+
my_string::my_string(auto const& string_, auto const& size_)
1366+
: string{ string_ }
1367+
, size{ size_ }{}
1368+
12731369
#line 857 "pure2-last-use.cpp2"
12741370
[[nodiscard]] auto no_pessimizing_move() -> no_pessimizing_move_ret{
12751371
std::unique_ptr<int> ret {};
@@ -1357,6 +1453,12 @@ auto f() -> void{
13571453
});
13581454
}
13591455

1456+
t::t(auto const& x_)
1457+
: x{ x_ }{}
1458+
1459+
auto t::operator=(auto const& x_) -> t& {
1460+
x = x_;
1461+
return *this;}
13601462
#line 940 "pure2-last-use.cpp2"
13611463
auto g() -> void{
13621464
static_cast<void>([]() mutable -> void{
@@ -1402,6 +1504,12 @@ auto loops_and_captures() -> void{
14021504
// };
14031505
}
14041506

1507+
types::types(auto const& x_)
1508+
: x{ x_ }{}
1509+
1510+
auto types::operator=(auto const& x_) -> types& {
1511+
x = x_;
1512+
return *this;}
14051513
#line 994 "pure2-last-use.cpp2"
14061514
auto skip_hidden_names() -> void{
14071515
static_cast<void>([]() mutable -> void{

regression-tests/test-results/pure2-print.cpp2.output

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ pure2-print.cpp2...
22

33
outer:/* @print */ type =
44
{
5-
object_alias: <T: type> T requires (true) == 42;
5+
object_alias: <T: type, > T requires (true) == 42;
66
mytype: final type =
77
{
88
protected f:() -> move int = 42;
99

1010
g:(
1111
virtual in this,
12-
in i: int
12+
in i: int,
1313
) -> move int =
1414
{
1515
using namespace ::std;
16-
s: = "string literal";
16+
s: _ = "string literal";
1717
ret: int = i;
1818
p: const * const int = ret&;
1919
if p* < 0
@@ -30,18 +30,18 @@ outer:/* @print */ type =
3030

3131
private h:(
3232
in s: std::string,
33-
inout m: std::map<const int, std::string>
33+
inout m: std::map<const int, std::string>,
3434
) -> move std::string
3535
pre( m.empty() == false || false, "message" )
3636
pre<bounds_safety,testing_enabled>( 0 < m.ssize() < 100 && true != false, ("size is " + cpp2::to_string(m.ssize())) ) =
3737
{
38-
a: = :() =
38+
a: _ = :() =
3939
{
4040
};
41-
b: = :() =
41+
b: _ = :() =
4242
{
4343
};
44-
c: = :() =
44+
c: _ = :() =
4545
{
4646
};
4747
while s.empty()
@@ -56,7 +56,7 @@ outer:/* @print */ type =
5656
while s.empty();
5757
label: for m
5858
next c()
59-
do (in _:)
59+
do (in _: _)
6060
{
6161
continue label;
6262
}
@@ -79,38 +79,38 @@ outer:/* @print */ type =
7979
return :() -> move std::string = (s + m[0])$;();
8080
}
8181

82-
values: <T: type>(
82+
values: <T: type, >(
8383
in this,
84-
in _: T
84+
in _: T,
8585
) throws -> (
8686
out offset: int,
87-
out name: std::string
87+
out name: std::string,
8888
) =
8989
{
9090
offset = 53;
9191
name = "plugh";
9292
return;
9393
}
9494

95-
operator=:(out this) =
95+
operator=:(out this, ) =
9696
{
9797
}
9898

9999
operator=:(
100100
out this,
101-
in that
101+
in that,
102102
) =
103103
{
104104
}
105105

106106
operator=:(
107107
implicit out this,
108-
in _: int
108+
in _: int,
109109
) =
110110
{
111111
}
112112

113-
variadic:(in x...: int) =
113+
variadic:(in x...: int, ) =
114114
{
115115
(std::cout << ... << x);
116116
}
@@ -132,20 +132,20 @@ outer:/* @print */ type =
132132
is _ = "default case";
133133
} << "\n";
134134
}
135-
x: <Ts...: type> type =
135+
x: <Ts...: type, > type =
136136
{
137137
tup: std::tuple<Ts...> = ();
138138
}
139139

140-
print: <Args...: type>(
140+
print: <Args...: type, >(
141141
inout out: std::ostream,
142-
in args...: Args
142+
in args...: Args,
143143
) requires (sizeof...(Args) >= 0u) =
144144
{
145145
(out << ... << args);
146146
}
147147

148-
all: <Args...: type>(in args...: Args) -> move bool = (... && args);
148+
all: <Args...: type, >(in args...: Args, ) -> move bool = (... && args);
149149
}
150150
ok (all Cpp2, passes safety checks)
151151

0 commit comments

Comments
 (0)