From 885392eab2f9d6bf957f01c1f8c1b53e144be188 Mon Sep 17 00:00:00 2001 From: Herb Sutter Date: Sun, 2 Apr 2023 11:00:08 -0700 Subject: [PATCH] Better fix for #291, closes #312 --- ...ypes-smf-and-that-1-provide-everything.cpp.output | 4 ---- ...hat-2-provide-mvconstruct-and-cpassign.cpp.output | 4 ---- ...hat-3-provide-mvconstruct-and-mvassign.cpp.output | 4 ---- ...d-that-4-provide-cpassign-and-mvassign.cpp.output | 4 ---- ...hat-5-provide-nothing-but-general-case.cpp.output | 4 ---- regression-tests/test-results/pure2-types-basics.cpp | 8 ++++---- .../pure2-types-order-independence-and-nesting.cpp | 4 ++-- ...pure2-types-smf-and-that-1-provide-everything.cpp | 12 ++++++------ ...f-and-that-2-provide-mvconstruct-and-cpassign.cpp | 12 ++++++------ ...f-and-that-3-provide-mvconstruct-and-mvassign.cpp | 12 ++++++------ ...-smf-and-that-4-provide-cpassign-and-mvassign.cpp | 12 ++++++------ ...f-and-that-5-provide-nothing-but-general-case.cpp | 12 ++++++------ .../test-results/pure2-types-that-parameters.cpp | 8 ++++---- source/cppfront.cpp | 12 ++++++++---- source/parse.h | 3 ++- 15 files changed, 50 insertions(+), 65 deletions(-) diff --git a/regression-tests/test-results/clang-12/pure2-types-smf-and-that-1-provide-everything.cpp.output b/regression-tests/test-results/clang-12/pure2-types-smf-and-that-1-provide-everything.cpp.output index 776a838d23..e69de29bb2 100644 --- a/regression-tests/test-results/clang-12/pure2-types-smf-and-that-1-provide-everything.cpp.output +++ b/regression-tests/test-results/clang-12/pure2-types-smf-and-that-1-provide-everything.cpp.output @@ -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. diff --git a/regression-tests/test-results/clang-12/pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp.output b/regression-tests/test-results/clang-12/pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp.output index ca47b0e8ee..e69de29bb2 100644 --- a/regression-tests/test-results/clang-12/pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp.output +++ b/regression-tests/test-results/clang-12/pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp.output @@ -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. diff --git a/regression-tests/test-results/clang-12/pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp.output b/regression-tests/test-results/clang-12/pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp.output index de3ef819d0..e69de29bb2 100644 --- a/regression-tests/test-results/clang-12/pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp.output +++ b/regression-tests/test-results/clang-12/pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp.output @@ -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. diff --git a/regression-tests/test-results/clang-12/pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp.output b/regression-tests/test-results/clang-12/pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp.output index 4670bf8d00..e69de29bb2 100644 --- a/regression-tests/test-results/clang-12/pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp.output +++ b/regression-tests/test-results/clang-12/pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp.output @@ -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. diff --git a/regression-tests/test-results/clang-12/pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp.output b/regression-tests/test-results/clang-12/pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp.output index b6c86374e0..e69de29bb2 100644 --- a/regression-tests/test-results/clang-12/pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp.output +++ b/regression-tests/test-results/clang-12/pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp.output @@ -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. diff --git a/regression-tests/test-results/pure2-types-basics.cpp b/regression-tests/test-results/pure2-types-basics.cpp index 6f74fbcf88..78788c8973 100644 --- a/regression-tests/test-results/pure2-types-basics.cpp +++ b/regression-tests/test-results/pure2-types-basics.cpp @@ -84,8 +84,8 @@ namespace N { } #line 6 "pure2-types-basics.cpp2" auto myclass::operator=(cpp2::in 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"; @@ -106,8 +106,8 @@ namespace N { } #line 13 "pure2-types-basics.cpp2" auto myclass::operator=(cpp2::in s) -> myclass& { - data = {99}; - more = {s}; + data = 99; + more = s; #line 16 "pure2-types-basics.cpp2" std::cout << "myclass: explicit from string\n"; diff --git a/regression-tests/test-results/pure2-types-order-independence-and-nesting.cpp b/regression-tests/test-results/pure2-types-order-independence-and-nesting.cpp index 13fda184ca..db2b6efe22 100644 --- a/regression-tests/test-results/pure2-types-order-independence-and-nesting.cpp +++ b/regression-tests/test-results/pure2-types-order-independence-and-nesting.cpp @@ -116,7 +116,7 @@ namespace N { #line 10 "pure2-types-order-independence-and-nesting.cpp2" auto X::operator=(cpp2::out 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"; @@ -140,7 +140,7 @@ namespace N { { } #line 49 "pure2-types-order-independence-and-nesting.cpp2" auto Y::operator=(cpp2::in x) -> Y& { - px = {x}; + px = x; return *this; #line 49 "pure2-types-order-independence-and-nesting.cpp2" } diff --git a/regression-tests/test-results/pure2-types-smf-and-that-1-provide-everything.cpp b/regression-tests/test-results/pure2-types-smf-and-that-1-provide-everything.cpp index 082474bf14..15021c7c43 100644 --- a/regression-tests/test-results/pure2-types-smf-and-that-1-provide-everything.cpp +++ b/regression-tests/test-results/pure2-types-smf-and-that-1-provide-everything.cpp @@ -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 "; @@ -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; @@ -96,8 +96,8 @@ auto main() -> int; } #line 22 "pure2-types-smf-and-that-1-provide-everything.cpp2" auto myclass::operator=(cpp2::in 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 "; diff --git a/regression-tests/test-results/pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp b/regression-tests/test-results/pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp index 8dcdb7b562..b3946ef0db 100644 --- a/regression-tests/test-results/pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp +++ b/regression-tests/test-results/pure2-types-smf-and-that-2-provide-mvconstruct-and-cpassign.cpp @@ -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 "; @@ -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 "; @@ -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 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 "; diff --git a/regression-tests/test-results/pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp b/regression-tests/test-results/pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp index 20876bfa56..71b765b177 100644 --- a/regression-tests/test-results/pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp +++ b/regression-tests/test-results/pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp @@ -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; @@ -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; @@ -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 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 "; diff --git a/regression-tests/test-results/pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp b/regression-tests/test-results/pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp index 102d9c91fb..7f84bb25f0 100644 --- a/regression-tests/test-results/pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp +++ b/regression-tests/test-results/pure2-types-smf-and-that-4-provide-cpassign-and-mvassign.cpp @@ -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 "; @@ -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; @@ -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 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 "; diff --git a/regression-tests/test-results/pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp b/regression-tests/test-results/pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp index 9f18cbc78f..ed66d53357 100644 --- a/regression-tests/test-results/pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp +++ b/regression-tests/test-results/pure2-types-smf-and-that-5-provide-nothing-but-general-case.cpp @@ -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; @@ -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; @@ -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 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 "; diff --git a/regression-tests/test-results/pure2-types-that-parameters.cpp b/regression-tests/test-results/pure2-types-that-parameters.cpp index fe72b92556..690cc3f128 100644 --- a/regression-tests/test-results/pure2-types-that-parameters.cpp +++ b/regression-tests/test-results/pure2-types-that-parameters.cpp @@ -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" @@ -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" diff --git a/source/cppfront.cpp b/source/cppfront.cpp index cd3079607b..07181313c9 100644 --- a/source/cppfront.cpp +++ b/source/cppfront.cpp @@ -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 @@ -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 + - "};" + ";" ); } } diff --git a/source/parse.h b/source/parse.h index 8546c1a8ec..3e87420643 100644 --- a/source/parse.h +++ b/source/parse.h @@ -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