Skip to content

Commit bf29741

Browse files
authored
test: update to test what is intented and clarify with comments (#587)
1 parent 6ce2643 commit bf29741

File tree

2 files changed

+31
-35
lines changed

2 files changed

+31
-35
lines changed
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
quantity: type = {
22
number: i32;
3-
operator=: (out this, i: std::in_place_t, x: i32) = {
4-
number = x;
5-
_ = i;
6-
}
7-
operator+=: (inout this, that) -> forward quantity = {
8-
number += that.number;
9-
return this;
10-
}
3+
operator=: (out this, x: i32) = number = x;
4+
operator+: (inout this, that) -> quantity = quantity(number + that.number);
115
}
126

13-
main: () = {
14-
x: quantity = (std::in_place, 1729);
15-
x += x;
7+
main: (args) = {
8+
x: quantity = (1729);
9+
_ = x + x; // Not `(void) x + x`; would attempt to add a `void` to `x`.
10+
_ = args; // Not `void(args)`; would attempt to declare `args` with `void` type.
1611
}

regression-tests/test-results/pure2-bugfix-for-discard-precedence.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,42 @@ class quantity;
1515
#line 1 "pure2-bugfix-for-discard-precedence.cpp2"
1616
class quantity {
1717
private: cpp2::i32 number;
18-
public: explicit quantity(cpp2::in<std::in_place_t> i, cpp2::in<cpp2::i32> x);
19-
18+
public: explicit quantity(cpp2::in<cpp2::i32> x);
19+
20+
#line 3 "pure2-bugfix-for-discard-precedence.cpp2"
21+
public: auto operator=(cpp2::in<cpp2::i32> x) -> quantity& ;
22+
public: [[nodiscard]] auto operator+(quantity const& that) -> quantity;
2023

21-
#line 7 "pure2-bugfix-for-discard-precedence.cpp2"
22-
public: auto operator+=(quantity const& that) -> quantity&;
23-
2424
public: quantity(quantity const&) = delete; /* No 'that' constructor, suppress copy */
2525
public: auto operator=(quantity const&) -> void = delete;
26-
27-
28-
#line 11 "pure2-bugfix-for-discard-precedence.cpp2"
26+
#line 5 "pure2-bugfix-for-discard-precedence.cpp2"
2927
};
3028

31-
auto main() -> int;
29+
auto main(int const argc_, char const* const* const argv_) -> int;
3230

3331

3432
//=== Cpp2 function definitions =================================================
3533

3634

3735
#line 3 "pure2-bugfix-for-discard-precedence.cpp2"
38-
quantity::quantity(cpp2::in<std::in_place_t> i, cpp2::in<cpp2::i32> x)
39-
: number{ x }
36+
quantity::quantity(cpp2::in<cpp2::i32> x)
37+
: number{ x }
4038
#line 3 "pure2-bugfix-for-discard-precedence.cpp2"
41-
{
42-
43-
static_cast<void>(i);
44-
}
45-
auto quantity::operator+=(quantity const& that) -> quantity&{
46-
number += that.number;
47-
return (*this);
48-
}
49-
50-
#line 13 "pure2-bugfix-for-discard-precedence.cpp2"
51-
auto main() -> int{
52-
quantity x {std::in_place, 1729};
53-
x += std::move(x);
39+
{ }
40+
#line 3 "pure2-bugfix-for-discard-precedence.cpp2"
41+
auto quantity::operator=(cpp2::in<cpp2::i32> x) -> quantity& {
42+
number = x;
43+
return *this;
44+
#line 3 "pure2-bugfix-for-discard-precedence.cpp2"
45+
}
46+
[[nodiscard]] auto quantity::operator+(quantity const& that) -> quantity { return quantity(number + that.number); }
47+
48+
#line 7 "pure2-bugfix-for-discard-precedence.cpp2"
49+
auto main(int const argc_, char const* const* const argv_) -> int{
50+
auto args = cpp2::make_args(argc_, argv_);
51+
#line 8 "pure2-bugfix-for-discard-precedence.cpp2"
52+
quantity x {1729};
53+
static_cast<void>(x + std::move(x));// Not `(void) x + x`; would attempt to add a `void` to `x`.
54+
static_cast<void>(args);// Not `void(args)`; would attempt to declare `args` with `void` type.
5455
}
5556

0 commit comments

Comments
 (0)