diff --git a/regression-tests/pure2-bugfix-for-assign-expression-list.cpp2 b/regression-tests/pure2-bugfix-for-assign-expression-list.cpp2 index 5341a7e608..328571a47e 100644 --- a/regression-tests/pure2-bugfix-for-assign-expression-list.cpp2 +++ b/regression-tests/pure2-bugfix-for-assign-expression-list.cpp2 @@ -1,5 +1,13 @@ +vec: type == std::vector; + +my_vec: type = { + v: vec = (); + operator=: (out this, _: std::integral_constant) = v = (); + operator=: (out this, _: std::integral_constant) = v = (1); + operator=: (out this, _: std::integral_constant) = v = (2, 3); +} + main: () = { - vec: type == std::vector; v: vec = (0); v = (); assert( v == :vec = () ); diff --git a/regression-tests/test-results/pure2-bugfix-for-assign-expression-list.cpp b/regression-tests/test-results/pure2-bugfix-for-assign-expression-list.cpp index 719ee11c59..68778c7376 100644 --- a/regression-tests/test-results/pure2-bugfix-for-assign-expression-list.cpp +++ b/regression-tests/test-results/pure2-bugfix-for-assign-expression-list.cpp @@ -8,18 +8,63 @@ #line 1 "pure2-bugfix-for-assign-expression-list.cpp2" +#line 3 "pure2-bugfix-for-assign-expression-list.cpp2" +class my_vec; + //=== Cpp2 type definitions and function declarations =========================== #line 1 "pure2-bugfix-for-assign-expression-list.cpp2" +using vec = std::vector; +#line 2 "pure2-bugfix-for-assign-expression-list.cpp2" + +class my_vec { + private: vec v {}; + public: explicit my_vec([[maybe_unused]] cpp2::impl::in> unnamed_param_2); +#line 5 "pure2-bugfix-for-assign-expression-list.cpp2" + public: auto operator=([[maybe_unused]] cpp2::impl::in> unnamed_param_2) -> my_vec& ; + public: explicit my_vec([[maybe_unused]] cpp2::impl::in> unnamed_param_2); +#line 6 "pure2-bugfix-for-assign-expression-list.cpp2" + public: auto operator=([[maybe_unused]] cpp2::impl::in> unnamed_param_2) -> my_vec& ; + public: explicit my_vec([[maybe_unused]] cpp2::impl::in> unnamed_param_2); +#line 7 "pure2-bugfix-for-assign-expression-list.cpp2" + public: auto operator=([[maybe_unused]] cpp2::impl::in> unnamed_param_2) -> my_vec& ; + public: my_vec(my_vec const&) = delete; /* No 'that' constructor, suppress copy */ + public: auto operator=(my_vec const&) -> void = delete; + +#line 8 "pure2-bugfix-for-assign-expression-list.cpp2" +}; + auto main() -> int; //=== Cpp2 function definitions ================================================= #line 1 "pure2-bugfix-for-assign-expression-list.cpp2" + +#line 5 "pure2-bugfix-for-assign-expression-list.cpp2" + my_vec::my_vec([[maybe_unused]] cpp2::impl::in> unnamed_param_2) + : v{ } { } +#line 5 "pure2-bugfix-for-assign-expression-list.cpp2" + auto my_vec::operator=([[maybe_unused]] cpp2::impl::in> unnamed_param_2) -> my_vec& { + v = { }; + return *this; } +#line 6 "pure2-bugfix-for-assign-expression-list.cpp2" + my_vec::my_vec([[maybe_unused]] cpp2::impl::in> unnamed_param_2) + : v{ 1 } { } +#line 6 "pure2-bugfix-for-assign-expression-list.cpp2" + auto my_vec::operator=([[maybe_unused]] cpp2::impl::in> unnamed_param_2) -> my_vec& { + v = { 1 }; + return *this; } +#line 7 "pure2-bugfix-for-assign-expression-list.cpp2" + my_vec::my_vec([[maybe_unused]] cpp2::impl::in> unnamed_param_2) + : v{ 2, 3 } { } +#line 7 "pure2-bugfix-for-assign-expression-list.cpp2" + auto my_vec::operator=([[maybe_unused]] cpp2::impl::in> unnamed_param_2) -> my_vec& { + v = { 2, 3 }; + return *this; } + +#line 10 "pure2-bugfix-for-assign-expression-list.cpp2" auto main() -> int{ -#line 2 "pure2-bugfix-for-assign-expression-list.cpp2" - using vec = std::vector; vec v {0}; v = { }; if (cpp2::cpp2_default.is_active() && !(v == vec{}) ) { cpp2::cpp2_default.report_violation(""); } diff --git a/source/to_cpp1.h b/source/to_cpp1.h index 73b904ecba..aa4b31e135 100644 --- a/source/to_cpp1.h +++ b/source/to_cpp1.h @@ -5451,6 +5451,14 @@ class cppfront if (found_explicit_init) { initializer = rhs; + if ( + is_assignment + && std::get((*statement)->statement) + ->expr->expr->terms[0].expr->is_expression_list() + ) + { + initializer = "{ " + rhs + " }"; + } // We've used this statement, so note it // and move 'statement' forward