Skip to content

Commit f608b78

Browse files
committed
Better fix for #291, closes #312
1 parent 63efa6e commit f608b78

15 files changed

+50
-65
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
pure2-types-smf-and-that-1-provide-everything.cpp2:24:16: warning: braces around scalar initializer [-Wbraced-scalar-init]
2-
addr = {"123 Ford Dr."};
3-
^~~~~~~~~~~~~~~~
4-
1 warning generated.
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2:24:16: warning: braces around scalar initializer [-Wbraced-scalar-init]
2-
addr = {"123 Ford Dr."};
3-
^~~~~~~~~~~~~~~~
4-
1 warning generated.
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2:24:16: warning: braces around scalar initializer [-Wbraced-scalar-init]
2-
addr = {"123 Ford Dr."};
3-
^~~~~~~~~~~~~~~~
4-
1 warning generated.
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2:24:16: warning: braces around scalar initializer [-Wbraced-scalar-init]
2-
addr = {"123 Ford Dr."};
3-
^~~~~~~~~~~~~~~~
4-
1 warning generated.
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2:24:16: warning: braces around scalar initializer [-Wbraced-scalar-init]
2-
addr = {"123 Ford Dr."};
3-
^~~~~~~~~~~~~~~~
4-
1 warning generated.

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ namespace N {
8484
}
8585
#line 6 "pure2-types-basics.cpp2"
8686
auto myclass::operator=(cpp2::in<int> x) -> myclass& {
87-
data = {x};
88-
more = {std::to_string(42 * 12)};
87+
data = x;
88+
more = std::to_string(42 * 12);
8989

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

112112
#line 16 "pure2-types-basics.cpp2"
113113
std::cout << "myclass: explicit from string\n";

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ namespace N {
116116
#line 10 "pure2-types-order-independence-and-nesting.cpp2"
117117
auto X::operator=(cpp2::out<Y> y) -> X& {
118118
y.construct(&(*this));
119-
py = {&y.value()};
119+
py = &y.value();
120120

121121
#line 31 "pure2-types-order-independence-and-nesting.cpp2"
122122
std::cout << "made a safely initialized cycle\n";
@@ -140,7 +140,7 @@ namespace N {
140140
{ }
141141
#line 49 "pure2-types-order-independence-and-nesting.cpp2"
142142
auto Y::operator=(cpp2::in<X*> x) -> Y& {
143-
px = {x};
143+
px = x;
144144
return *this;
145145
#line 49 "pure2-types-order-independence-and-nesting.cpp2"
146146
}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ auto main() -> int;
6969
}
7070

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

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

8181
auto myclass::operator=(myclass&& that) -> myclass& {
82-
name = {std::move(that).name};
83-
addr = {std::move(that).addr};
82+
name = std::move(that).name;
83+
addr = std::move(that).addr;
8484
#line 19 "pure2-types-smf-and-that-1-provide-everything.cpp2"
8585
std::cout << "assign - move ";
8686
return *this;
@@ -96,8 +96,8 @@ auto main() -> int;
9696
}
9797
#line 22 "pure2-types-smf-and-that-1-provide-everything.cpp2"
9898
auto myclass::operator=(cpp2::in<std::string> x) -> myclass& {
99-
name = {x};
100-
addr = {"123 Ford Dr."};
99+
name = x;
100+
addr = "123 Ford Dr.";
101101

102102
#line 24 "pure2-types-smf-and-that-1-provide-everything.cpp2"
103103
std::cout << "ctor - from string ";

regression-tests/test-results/pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ auto main() -> int;
7272
}
7373

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

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

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

107107
#line 24 "pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp2"
108108
std::cout << "ctor - from string ";

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ auto main() -> int;
6464
}
6565
#line 4 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
6666
auto myclass::operator=(myclass const& that) -> myclass& {
67-
name = {that.name};
68-
addr = {that.addr};
67+
name = that.name;
68+
addr = that.addr;
6969
#line 5 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
7070
std::cout << "ctor - copy (GENERAL)";
7171
return *this;
@@ -83,8 +83,8 @@ auto main() -> int;
8383

8484
#line 18 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
8585
auto myclass::operator=(myclass&& that) -> myclass& {
86-
name = {std::move(that).name};
87-
addr = {std::move(that).addr};
86+
name = std::move(that).name;
87+
addr = std::move(that).addr;
8888
#line 19 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
8989
std::cout << "assign - move ";
9090
return *this;
@@ -100,8 +100,8 @@ auto main() -> int;
100100
}
101101
#line 22 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
102102
auto myclass::operator=(cpp2::in<std::string> x) -> myclass& {
103-
name = {x};
104-
addr = {"123 Ford Dr."};
103+
name = x;
104+
addr = "123 Ford Dr.";
105105

106106
#line 24 "pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp2"
107107
std::cout << "ctor - from string ";

regression-tests/test-results/pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ auto main() -> int;
7373

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

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

8585
auto myclass::operator=(myclass&& that) -> myclass& {
86-
name = {std::move(that).name};
87-
addr = {std::move(that).addr};
86+
name = std::move(that).name;
87+
addr = std::move(that).addr;
8888
#line 19 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
8989
std::cout << "assign - move ";
9090
return *this;
@@ -100,8 +100,8 @@ auto main() -> int;
100100
}
101101
#line 22 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
102102
auto myclass::operator=(cpp2::in<std::string> x) -> myclass& {
103-
name = {x};
104-
addr = {"123 Ford Dr."};
103+
name = x;
104+
addr = "123 Ford Dr.";
105105

106106
#line 24 "pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp2"
107107
std::cout << "ctor - from string ";

regression-tests/test-results/pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ auto main() -> int;
7171
}
7272
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
7373
auto myclass::operator=(myclass const& that) -> myclass& {
74-
name = {that.name};
75-
addr = {that.addr};
74+
name = that.name;
75+
addr = that.addr;
7676
#line 5 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
7777
std::cout << "ctor - copy (GENERAL)";
7878
return *this;
@@ -88,8 +88,8 @@ auto main() -> int;
8888
}
8989
#line 4 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
9090
auto myclass::operator=(myclass&& that) -> myclass& {
91-
name = {std::move(that).name};
92-
addr = {std::move(that).addr};
91+
name = std::move(that).name;
92+
addr = std::move(that).addr;
9393
#line 5 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
9494
std::cout << "ctor - copy (GENERAL)";
9595
return *this;
@@ -106,8 +106,8 @@ auto main() -> int;
106106
}
107107
#line 22 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
108108
auto myclass::operator=(cpp2::in<std::string> x) -> myclass& {
109-
name = {x};
110-
addr = {"123 Ford Dr."};
109+
name = x;
110+
addr = "123 Ford Dr.";
111111

112112
#line 24 "pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp2"
113113
std::cout << "ctor - from string ";

regression-tests/test-results/pure2-types-that-parameters.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ auto main() -> int;
5454
}
5555
#line 6 "pure2-types-that-parameters.cpp2"
5656
auto myclass::operator=(myclass const& that) -> myclass& {
57-
name = {that.name};
58-
addr = {that.addr};
57+
name = that.name;
58+
addr = that.addr;
5959
return *this;
6060

6161
#line 9 "pure2-types-that-parameters.cpp2"
@@ -71,8 +71,8 @@ auto main() -> int;
7171
}
7272
#line 11 "pure2-types-that-parameters.cpp2"
7373
auto myclass::operator=(myclass&& that) -> myclass& {
74-
name = {std::move(that).name};
75-
addr = {std::move(that).addr};
74+
name = std::move(that).name;
75+
addr = std::move(that).addr;
7676
return *this;
7777

7878
#line 14 "pure2-types-that-parameters.cpp2"

source/cppfront.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -4298,9 +4298,9 @@ class cppfront
42984298

42994299
current_functions.back().prolog.statements.push_back(
43004300
(*object)->name()->to_string(true) +
4301-
" = {" +
4301+
" = " +
43024302
initializer +
4303-
"};"
4303+
";"
43044304
);
43054305
}
43064306
// (b) ... if this isn't assignment, only need to emit it if it was
@@ -4365,11 +4365,15 @@ class cppfront
43654365
if (is_assignment)
43664366
{
43674367
auto initializer = print_to_string( *(*object)->initializer, false );
4368+
if (initializer.empty()) {
4369+
initializer = "{}";
4370+
}
4371+
43684372
current_functions.back().prolog.statements.push_back(
43694373
(*object)->name()->to_string(true) +
4370-
" = {" +
4374+
" = " +
43714375
initializer +
4372-
"};"
4376+
";"
43734377
);
43744378
}
43754379
}

source/parse.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -5240,7 +5240,8 @@ class parser
52405240
//G ':' template-parameter-declaration-list? '_'? '==' expression ';'
52415241
//G
52425242
//GT ':' function-type '==' expression ';'
5243-
//GT # See commit comment for why I don't see a need to enable this yet
5243+
//GT # See commit 63efa6ed21c4d4f4f136a7a73e9f6b2c110c81d7 comment
5244+
//GT # for why I don't see a need to enable this yet
52445245
//
52455246
auto alias()
52465247
-> std::unique_ptr<declaration_node>

0 commit comments

Comments
 (0)