From 347f374550c970560e2516930baa03526fcfe100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johel=20Ernesto=20Guerrero=20Pe=C3=B1a?= Date: Sun, 13 Aug 2023 21:07:07 -0400 Subject: [PATCH] test: update to test what is intented and clarify with comments (#587) --- .../pure2-bugfix-for-discard-precedence.cpp2 | 17 +++---- .../pure2-bugfix-for-discard-precedence.cpp | 49 ++++++++++--------- 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/regression-tests/pure2-bugfix-for-discard-precedence.cpp2 b/regression-tests/pure2-bugfix-for-discard-precedence.cpp2 index 40264e3163..88b437d2ad 100644 --- a/regression-tests/pure2-bugfix-for-discard-precedence.cpp2 +++ b/regression-tests/pure2-bugfix-for-discard-precedence.cpp2 @@ -1,16 +1,11 @@ quantity: type = { number: i32; - operator=: (out this, i: std::in_place_t, x: i32) = { - number = x; - _ = i; - } - operator+=: (inout this, that) -> forward quantity = { - number += that.number; - return this; - } + operator=: (out this, x: i32) = number = x; + operator+: (inout this, that) -> quantity = quantity(number + that.number); } -main: () = { - x: quantity = (std::in_place, 1729); - x += x; +main: (args) = { + x: quantity = (1729); + _ = x + x; // Not `(void) x + x`; would attempt to add a `void` to `x`. + _ = args; // Not `void(args)`; would attempt to declare `args` with `void` type. } diff --git a/regression-tests/test-results/pure2-bugfix-for-discard-precedence.cpp b/regression-tests/test-results/pure2-bugfix-for-discard-precedence.cpp index 0266e0c427..292b8185e0 100644 --- a/regression-tests/test-results/pure2-bugfix-for-discard-precedence.cpp +++ b/regression-tests/test-results/pure2-bugfix-for-discard-precedence.cpp @@ -15,41 +15,42 @@ class quantity; #line 1 "pure2-bugfix-for-discard-precedence.cpp2" class quantity { private: cpp2::i32 number; - public: explicit quantity(cpp2::in i, cpp2::in x); - + public: explicit quantity(cpp2::in x); + +#line 3 "pure2-bugfix-for-discard-precedence.cpp2" + public: auto operator=(cpp2::in x) -> quantity& ; + public: [[nodiscard]] auto operator+(quantity const& that) -> quantity; -#line 7 "pure2-bugfix-for-discard-precedence.cpp2" - public: auto operator+=(quantity const& that) -> quantity&; - public: quantity(quantity const&) = delete; /* No 'that' constructor, suppress copy */ public: auto operator=(quantity const&) -> void = delete; - - -#line 11 "pure2-bugfix-for-discard-precedence.cpp2" +#line 5 "pure2-bugfix-for-discard-precedence.cpp2" }; -auto main() -> int; +auto main(int const argc_, char const* const* const argv_) -> int; //=== Cpp2 function definitions ================================================= #line 3 "pure2-bugfix-for-discard-precedence.cpp2" - quantity::quantity(cpp2::in i, cpp2::in x) - : number{ x } + quantity::quantity(cpp2::in x) + : number{ x } #line 3 "pure2-bugfix-for-discard-precedence.cpp2" - { - - static_cast(i); - } - auto quantity::operator+=(quantity const& that) -> quantity&{ - number += that.number; - return (*this); - } - -#line 13 "pure2-bugfix-for-discard-precedence.cpp2" -auto main() -> int{ - quantity x {std::in_place, 1729}; - x += std::move(x); + { } +#line 3 "pure2-bugfix-for-discard-precedence.cpp2" + auto quantity::operator=(cpp2::in x) -> quantity& { + number = x; + return *this; +#line 3 "pure2-bugfix-for-discard-precedence.cpp2" + } + [[nodiscard]] auto quantity::operator+(quantity const& that) -> quantity { return quantity(number + that.number); } + +#line 7 "pure2-bugfix-for-discard-precedence.cpp2" +auto main(int const argc_, char const* const* const argv_) -> int{ + auto args = cpp2::make_args(argc_, argv_); +#line 8 "pure2-bugfix-for-discard-precedence.cpp2" + quantity x {1729}; + static_cast(x + std::move(x));// Not `(void) x + x`; would attempt to add a `void` to `x`. + static_cast(args);// Not `void(args)`; would attempt to declare `args` with `void` type. }