Skip to content

Commit e0125d7

Browse files
committed
Changed out x argument to pass out(&x) for better deduction, see #369 comment thread
1 parent 6ea55d2 commit e0125d7

8 files changed

+21
-17
lines changed

regression-tests/test-results/mixed-initialization-safety-3-contract-violation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool flip_a_coin() {
4545
if (flip_a_coin()) {
4646
x.construct("xyzzy");
4747
}else {
48-
fill(&x, "plugh", 40); // note: constructs x!
48+
fill(cpp2::out(&x), "plugh", 40);// note: constructs x!
4949
}
5050
print_decorated(std::move(x.value()));
5151
}

regression-tests/test-results/mixed-initialization-safety-3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ auto print_decorated(auto const& x) -> void;
4242
if (flip_a_coin()) {
4343
x.construct("xyzzy");
4444
}else {
45-
fill(&x, "plugh", 40); // note: constructs x!
45+
fill(cpp2::out(&x), "plugh", 40);// note: constructs x!
4646
}
4747
print_decorated(std::move(x.value()));
4848
}

regression-tests/test-results/mixed-out-destruction.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ int main() {
5454

5555

5656
#line 22 "mixed-out-destruction.cpp2"
57-
auto f00() -> void { C c {"f00"}; cpp2::deferred_init<X> x; f01(&x);}
57+
auto f00() -> void { C c {"f00"}; cpp2::deferred_init<X> x; f01(cpp2::out(&x));}
5858
auto f01(cpp2::out<X> x) -> void{C c {"f01"}; x.construct();throw_1();}
5959

6060
#line 27 "mixed-out-destruction.cpp2"
61-
auto f10() -> void { C c {"f10"}; cpp2::deferred_init<X> x; f11(&x);}
62-
auto f11(cpp2::out<X> x) -> void{C c {"f11"}; f12(&x);}
63-
auto f12(cpp2::out<X> x) -> void{C c {"f12"}; f13(&x);throw_1();}
64-
auto f13(cpp2::out<X> x) -> void{C c {"f13"}; f14(&x);}
61+
auto f10() -> void { C c {"f10"}; cpp2::deferred_init<X> x; f11(cpp2::out(&x));}
62+
auto f11(cpp2::out<X> x) -> void{C c {"f11"}; f12(cpp2::out(&x));}
63+
auto f12(cpp2::out<X> x) -> void{C c {"f12"}; f13(cpp2::out(&x));throw_1();}
64+
auto f13(cpp2::out<X> x) -> void{C c {"f13"}; f14(cpp2::out(&x));}
6565
auto f14(cpp2::out<X> x) -> void{C c {"f14"}; x.construct();}
6666

regression-tests/test-results/mixed-parameter-passing-generic-out.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ auto operator<<(std::ostream& o, X const&) -> std::ostream& {
2020
}
2121

2222
#line 11 "mixed-parameter-passing-generic-out.cpp2"
23-
auto f(auto* x_) -> void;
23+
auto f(auto x_) -> void;
2424

2525

2626
#line 15 "mixed-parameter-passing-generic-out.cpp2"
@@ -31,19 +31,19 @@ auto f(auto* x_) -> void;
3131

3232

3333
#line 11 "mixed-parameter-passing-generic-out.cpp2"
34-
auto f(auto* x_) -> void{
34+
auto f(auto x_) -> void{
3535
auto x = cpp2::out(x_);
3636
#line 12 "mixed-parameter-passing-generic-out.cpp2"
3737
x.construct(42);
3838
}
3939

4040
[[nodiscard]] auto main() -> int{
4141
cpp2::deferred_init<int> a;
42-
f(&a);
42+
f(cpp2::out(&a));
4343
std::cout << std::move(a.value()) << "\n";
4444

4545
cpp2::deferred_init<X> b;
46-
f(&b);
46+
f(cpp2::out(&b));
4747
std::cout << std::move(b.value()) << "\n";
4848
}
4949

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ namespace M {
189189
auto main() -> int
190190
{
191191
cpp2::deferred_init<N::Y> y; // declare an uninitialized Y object
192-
N::X x {&y}; // construct y and x, and point them at each other
192+
N::X x {cpp2::out(&y)}; // construct y and x, and point them at each other
193193

194194
// now have the two objects call each other back and forth a few times
195195
CPP2_UFCS(exx, std::move(x), 1);

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 8520:1425
2+
cppfront compiler v0.2.1 Build 8521:0840
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-
"8520:1425"
1+
"8521:0840"

source/cppfront.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3551,7 +3551,7 @@ class cppfront
35513551
);
35523552
if (x.pass == passing_style::out) {
35533553
is_out = true;
3554-
printer.print_cpp2("&", n.position());
3554+
printer.print_cpp2("cpp2::out(&", n.position());
35553555
}
35563556
else if (x.pass == passing_style::move) {
35573557
printer.print_cpp2("std::move(", n.position());
@@ -3571,7 +3571,11 @@ class cppfront
35713571
in_non_rvalue_context.pop_back();
35723572
}
35733573

3574-
if (x.pass == passing_style::move) {
3574+
if (
3575+
x.pass == passing_style::move
3576+
|| x.pass == passing_style::out
3577+
)
3578+
{
35753579
printer.print_cpp2(")", n.position());
35763580
}
35773581
}
@@ -3914,7 +3918,7 @@ class cppfront
39143918

39153919
// For generic out parameters, we take a pointer to anything with paramater named "identifier_"
39163920
// and then generate the out<> as a stack local with the expected name "identifier"
3917-
break;case passing_style::out : printer.print_cpp2( name+"*", n.position() );
3921+
break;case passing_style::out : printer.print_cpp2( name, n.position() );
39183922
current_functions.back().prolog.statements.push_back(
39193923
"auto " + identifier + " = cpp2::out(" + identifier + "_); "
39203924
);

0 commit comments

Comments
 (0)