Skip to content

Commit

Permalink
Better fix for hsutter#291, closes hsutter#312
Browse files Browse the repository at this point in the history
  • Loading branch information
hsutter authored and zaucy committed Dec 5, 2023
1 parent c2da23c commit 885392e
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
pure2-types-smf-and-that-1-provide-everything.cpp2:24:16: warning: braces around scalar initializer [-Wbraced-scalar-init]
addr = {"123 Ford Dr."};
^~~~~~~~~~~~~~~~
1 warning generated.
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2:24:16: warning: braces around scalar initializer [-Wbraced-scalar-init]
addr = {"123 Ford Dr."};
^~~~~~~~~~~~~~~~
1 warning generated.
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2:24:16: warning: braces around scalar initializer [-Wbraced-scalar-init]
addr = {"123 Ford Dr."};
^~~~~~~~~~~~~~~~
1 warning generated.
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2:24:16: warning: braces around scalar initializer [-Wbraced-scalar-init]
addr = {"123 Ford Dr."};
^~~~~~~~~~~~~~~~
1 warning generated.
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2:24:16: warning: braces around scalar initializer [-Wbraced-scalar-init]
addr = {"123 Ford Dr."};
^~~~~~~~~~~~~~~~
1 warning generated.
8 changes: 4 additions & 4 deletions regression-tests/test-results/pure2-types-basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ namespace N {
}
#line 6 "pure2-types-basics.cpp2"
auto myclass::operator=(cpp2::in<int> x) -> myclass& {
data = {x};
more = {std::to_string(42 * 12)};
data = x;
more = std::to_string(42 * 12);

#line 9 "pure2-types-basics.cpp2"
std::cout << "myclass: implicit from int\n";
Expand All @@ -106,8 +106,8 @@ namespace N {
}
#line 13 "pure2-types-basics.cpp2"
auto myclass::operator=(cpp2::in<std::string> s) -> myclass& {
data = {99};
more = {s};
data = 99;
more = s;

#line 16 "pure2-types-basics.cpp2"
std::cout << "myclass: explicit from string\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace N {
#line 10 "pure2-types-order-independence-and-nesting.cpp2"
auto X::operator=(cpp2::out<Y> y) -> X& {
y.construct(&(*this));
py = {&y.value()};
py = &y.value();

#line 31 "pure2-types-order-independence-and-nesting.cpp2"
std::cout << "made a safely initialized cycle\n";
Expand All @@ -140,7 +140,7 @@ namespace N {
{ }
#line 49 "pure2-types-order-independence-and-nesting.cpp2"
auto Y::operator=(cpp2::in<X*> x) -> Y& {
px = {x};
px = x;
return *this;
#line 49 "pure2-types-order-independence-and-nesting.cpp2"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ auto main() -> int;
}

auto myclass::operator=(myclass const& that) -> myclass& {
name = {that.name};
addr = {that.addr + "(AC)"};
name = that.name;
addr = that.addr + "(AC)";

#line 15 "pure2-types-smf-and-that-1-provide-everything.cpp2"
std::cout << "assign - copy ";
Expand All @@ -79,8 +79,8 @@ auto main() -> int;
}

auto myclass::operator=(myclass&& that) -> myclass& {
name = {std::move(that).name};
addr = {std::move(that).addr};
name = std::move(that).name;
addr = std::move(that).addr;
#line 19 "pure2-types-smf-and-that-1-provide-everything.cpp2"
std::cout << "assign - move ";
return *this;
Expand All @@ -96,8 +96,8 @@ auto main() -> int;
}
#line 22 "pure2-types-smf-and-that-1-provide-everything.cpp2"
auto myclass::operator=(cpp2::in<std::string> x) -> myclass& {
name = {x};
addr = {"123 Ford Dr."};
name = x;
addr = "123 Ford Dr.";

#line 24 "pure2-types-smf-and-that-1-provide-everything.cpp2"
std::cout << "ctor - from string ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ auto main() -> int;
}

auto myclass::operator=(myclass const& that) -> myclass& {
name = {that.name};
addr = {that.addr + "(AC)"};
name = that.name;
addr = that.addr + "(AC)";

#line 15 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
std::cout << "assign - copy ";
Expand All @@ -82,8 +82,8 @@ auto main() -> int;
}
#line 13 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
auto myclass::operator=(myclass&& that) -> myclass& {
name = {std::move(that).name};
addr = {std::move(that).addr + "(AC)"};
name = std::move(that).name;
addr = std::move(that).addr + "(AC)";

#line 15 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
std::cout << "assign - copy ";
Expand All @@ -101,8 +101,8 @@ auto main() -> int;
}
#line 22 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
auto myclass::operator=(cpp2::in<std::string> x) -> myclass& {
name = {x};
addr = {"123 Ford Dr."};
name = x;
addr = "123 Ford Dr.";

#line 24 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
std::cout << "ctor - from string ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ auto main() -> int;
}
#line 4 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
auto myclass::operator=(myclass const& that) -> myclass& {
name = {that.name};
addr = {that.addr};
name = that.name;
addr = that.addr;
#line 5 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
std::cout << "ctor - copy (GENERAL)";
return *this;
Expand All @@ -83,8 +83,8 @@ auto main() -> int;

#line 18 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
auto myclass::operator=(myclass&& that) -> myclass& {
name = {std::move(that).name};
addr = {std::move(that).addr};
name = std::move(that).name;
addr = std::move(that).addr;
#line 19 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
std::cout << "assign - move ";
return *this;
Expand All @@ -100,8 +100,8 @@ auto main() -> int;
}
#line 22 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
auto myclass::operator=(cpp2::in<std::string> x) -> myclass& {
name = {x};
addr = {"123 Ford Dr."};
name = x;
addr = "123 Ford Dr.";

#line 24 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
std::cout << "ctor - from string ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ auto main() -> int;

#line 13 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
auto myclass::operator=(myclass const& that) -> myclass& {
name = {that.name};
addr = {that.addr + "(AC)"};
name = that.name;
addr = that.addr + "(AC)";

#line 15 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
std::cout << "assign - copy ";
Expand All @@ -83,8 +83,8 @@ auto main() -> int;
}

auto myclass::operator=(myclass&& that) -> myclass& {
name = {std::move(that).name};
addr = {std::move(that).addr};
name = std::move(that).name;
addr = std::move(that).addr;
#line 19 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
std::cout << "assign - move ";
return *this;
Expand All @@ -100,8 +100,8 @@ auto main() -> int;
}
#line 22 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
auto myclass::operator=(cpp2::in<std::string> x) -> myclass& {
name = {x};
addr = {"123 Ford Dr."};
name = x;
addr = "123 Ford Dr.";

#line 24 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
std::cout << "ctor - from string ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ auto main() -> int;
}
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
auto myclass::operator=(myclass const& that) -> myclass& {
name = {that.name};
addr = {that.addr};
name = that.name;
addr = that.addr;
#line 5 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
std::cout << "ctor - copy (GENERAL)";
return *this;
Expand All @@ -88,8 +88,8 @@ auto main() -> int;
}
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
auto myclass::operator=(myclass&& that) -> myclass& {
name = {std::move(that).name};
addr = {std::move(that).addr};
name = std::move(that).name;
addr = std::move(that).addr;
#line 5 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
std::cout << "ctor - copy (GENERAL)";
return *this;
Expand All @@ -106,8 +106,8 @@ auto main() -> int;
}
#line 22 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
auto myclass::operator=(cpp2::in<std::string> x) -> myclass& {
name = {x};
addr = {"123 Ford Dr."};
name = x;
addr = "123 Ford Dr.";

#line 24 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
std::cout << "ctor - from string ";
Expand Down
8 changes: 4 additions & 4 deletions regression-tests/test-results/pure2-types-that-parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ auto main() -> int;
}
#line 6 "pure2-types-that-parameters.cpp2"
auto myclass::operator=(myclass const& that) -> myclass& {
name = {that.name};
addr = {that.addr};
name = that.name;
addr = that.addr;
return *this;

#line 9 "pure2-types-that-parameters.cpp2"
Expand All @@ -71,8 +71,8 @@ auto main() -> int;
}
#line 11 "pure2-types-that-parameters.cpp2"
auto myclass::operator=(myclass&& that) -> myclass& {
name = {std::move(that).name};
addr = {std::move(that).addr};
name = std::move(that).name;
addr = std::move(that).addr;
return *this;

#line 14 "pure2-types-that-parameters.cpp2"
Expand Down
12 changes: 8 additions & 4 deletions source/cppfront.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4298,9 +4298,9 @@ class cppfront

current_functions.back().prolog.statements.push_back(
(*object)->name()->to_string(true) +
" = {" +
" = " +
initializer +
"};"
";"
);
}
// (b) ... if this isn't assignment, only need to emit it if it was
Expand Down Expand Up @@ -4365,11 +4365,15 @@ class cppfront
if (is_assignment)
{
auto initializer = print_to_string( *(*object)->initializer, false );
if (initializer.empty()) {
initializer = "{}";
}

current_functions.back().prolog.statements.push_back(
(*object)->name()->to_string(true) +
" = {" +
" = " +
initializer +
"};"
";"
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -5240,7 +5240,8 @@ class parser
//G ':' template-parameter-declaration-list? '_'? '==' expression ';'
//G
//GT ':' function-type '==' expression ';'
//GT # See commit comment for why I don't see a need to enable this yet
//GT # See commit 63efa6ed21c4d4f4f136a7a73e9f6b2c110c81d7 comment
//GT # for why I don't see a need to enable this yet
//
auto alias()
-> std::unique_ptr<declaration_node>
Expand Down

0 comments on commit 885392e

Please sign in to comment.