Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statements before and between member initializers in special member functions #518

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
myclass : type = {

operator=: (out this, that) = {
this = that;
std::cout << "ctor - copy (GENERAL)";
}

operator=: (out this, move that) = {
this = that;
name = that.name + "(CM)";
std::cout << "ctor - move ";
}

operator=: (inout this, that) = {
this = that;
addr = that.addr + "(AC)";
std::cout << "assign - copy ";
}

operator=: (inout this, move that) = {
this = that;
std::cout << "assign - move ";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
myclass : type = {

operator=: (out this, that) = {
this = that;
std::cout << "ctor - copy (GENERAL)";
}

operator=: (out this, move that) = {
this = that;
name = that.name + "(CM)";
std::cout << "ctor - move ";
}

operator=: (inout this, that) = {
this = that;
addr = that.addr + "(AC)";
std::cout << "assign - copy ";
}

// operator=: (inout this, move that) = {
// this = that;
// std::cout << "assign - move ";
// }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
myclass : type = {

operator=: (out this, that) = {
this = that;
std::cout << "ctor - copy (GENERAL)";
}

operator=: (out this, move that) = {
this = that;
name = that.name + "(CM)";
std::cout << "ctor - move ";
}

// operator=: (inout this, that) = {
// this = that;
// addr = that.addr + "(AC)";
// std::cout << "assign - copy ";
// }

operator=: (inout this, move that) = {
this = that;
std::cout << "assign - move ";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
myclass : type = {

operator=: (out this, that) = {
this = that;
std::cout << "ctor - copy (GENERAL)";
}

// operator=: (out this, move that) = {
// this = that;
// name = that.name + "(CM)";
// std::cout << "ctor - move ";
// }

operator=: (inout this, that) = {
this = that;
addr = that.addr + "(AC)";
std::cout << "assign - copy ";
}

operator=: (inout this, move that) = {
this = that;
std::cout << "assign - move ";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
myclass : type = {

operator=: (out this, that) = {
this = that;
std::cout << "ctor - copy (GENERAL)";
}

// operator=: (out this, move that) = {
// this = that;
// name = that.name + "(CM)";
// std::cout << "ctor - move ";
// }

// operator=: (inout this, that) = {
// this = that;
// addr = that.addr + "(AC)";
// std::cout << "assign - copy ";
// }

// operator=: (inout this, move that) = {
// this = that;
// std::cout << "assign - move ";
// }

Expand Down
158 changes: 158 additions & 0 deletions regression-tests/pure2-types-smf-statements-between-member-inits.cpp2
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
f: (a1: i32) = {
_ = a1;
}

t1: type = {
m1: i32 = 123;
m2: i32 = 456;

operator=: (out this, that) = {
// m1 = 123 implied
// m2 = 456 implied
f(1);
f(2);
}
}

t2: type = {
m1: i32 = 123;
m2: i32 = 456;

operator=: (out this, that) = {
f(1);
f(2);
m1 = 3;
// m2 = 456 implied
f(4);
f(5);
}
}

t3: type = {
m1: i32 = 123;
m2: i32 = 456;

operator=: (out this, that) = {
// m1 = 123 implied
f(1);
f(2);
m2 = 3;
f(4);
f(5);
}
}

t4: type = {
m1: i32 = 123;
m2: i32 = 456;

operator=: (out this, that) = {
f(1);
f(2);
m1 = 3;
f(4);
f(5);
m2 = 6;
f(7);
f(8);
}
}

t5: type = {
m1: i32 = 123;
m2: i32 = 456;

operator=: (out this, that) = {
f(1);
f(2);
this = that;
// m1 = that.m1 implied
// m2 = that.m2 implied
// This comment should show up before f(3)
f(3);
f(4);
}
}

t6: type = {
m1: i32 = 123;
m2: i32 = 456;

operator=: (out this, that) = {
f(1);
f(2);
this = that;
f(3);
f(4);
m1 = 5;
// m2 = that.m2 implied
// This comment should show up before f(6)
f(6);
f(7);
}
}

t7: type = {
m1: i32 = 123;
m2: i32 = 456;

operator=: (out this, that) = {
f(1);
f(2);
this = that;
// m1 = that.m1 implied
f(3);
f(4);
m2 = 5;
// This comment should show up before f(6)
f(6);
f(7);
}
}

t8: type = {
m1: i32 = 123;
m2: i32 = 456;

operator=: (out this, that) = {
f(1);
f(2);
this = that;
f(3);
f(4);
m1 = 5;
f(6);
f(7);
m2 = 8;
// This comment should show up before f(9)
f(9);
f(10);
}
}

t9: type = {
m1: i32 = 123;
m2: i32 = 456;

operator=: (implicit out this, a1: i32) = {
_ = a1;
f(1);
f(2);
m1 = 3;
f(4);
f(5);
m2 = 6;
// This comment should show up before f(7)
f(7);
f(8);
}

operator=: (inout this, that) = {
// This function shouldn't contain any member assignments.
// While it's a special member function that uses 'that',
// it's explicitly an assignment operator because of 'inout this',
// so we let the programmer avoid member assignment if they choose.
f(1);
f(2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ namespace N {

#line 10 "pure2-types-order-independence-and-nesting.cpp2"
X::X(cpp2::out<Y> y)
: py{(y.construct(&(*this)), &y.value() )}
: py{ [&]() -> decltype(auto) {
y.construct(&(*this));
return &y.value();
}() }
#line 10 "pure2-types-order-independence-and-nesting.cpp2"
{
// === The following comments will stay close to, but not exactly at,
Expand Down
Loading