Skip to content

Commit 16a2296

Browse files
committed
test: add test case for discard precedence
1 parent 5665255 commit 16a2296

5 files changed

+84
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
quantity: type = {
2+
number: i32;
3+
operator=: (out this, _: std::in_place_t, x: i32) = {
4+
number = x;
5+
_ = _;
6+
}
7+
operator+=: (inout this, that) -> forward quantity = {
8+
_ = number += that.number;
9+
return this;
10+
}
11+
}
12+
13+
main: () = {
14+
x: quantity = (std::in_place, 1729);
15+
_ = x += x;
16+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
clang version 18.0.0 (https://git.uplinklabs.net/mirrors/llvm-project.git c0abd3814564a568dfc607c216e6407eaa314f46)
2+
Target: x86_64-pc-linux-gnu
3+
Thread model: posix
4+
InstalledDir: /home/johel/root/clang-main/bin
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pure2-bugfix-for-discard-precedence.cpp2:8:19: error: invalid operands to binary expression ('void' and 'const cpp2::i32' (aka 'const int'))
2+
8 | (void) number += that.number;
3+
| ~~~~~~~~~~~~~ ^ ~~~~~~~~~~~
4+
pure2-bugfix-for-discard-precedence.cpp2:15:12: error: invalid operands to binary expression ('void' and '__libcpp_remove_reference_t<quantity &>' (aka 'quantity'))
5+
15 | (void) x += std::move(x);
6+
| ~~~~~~~~ ^ ~~~~~~~~~~~~
7+
2 errors generated.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
#define CPP2_USE_MODULES Yes
3+
4+
//=== Cpp2 type declarations ====================================================
5+
6+
7+
#include "cpp2util.h"
8+
9+
#line 1 "pure2-bugfix-for-discard-precedence.cpp2"
10+
class quantity;
11+
12+
13+
//=== Cpp2 type definitions and function declarations ===========================
14+
15+
#line 1 "pure2-bugfix-for-discard-precedence.cpp2"
16+
class quantity {
17+
private: cpp2::i32 number;
18+
public: explicit quantity(cpp2::in<std::in_place_t> _, cpp2::in<cpp2::i32> x);
19+
20+
21+
#line 7 "pure2-bugfix-for-discard-precedence.cpp2"
22+
public: [[nodiscard]] auto operator+=(quantity const& that) -> quantity&;
23+
24+
public: quantity(quantity const&) = delete; /* No 'that' constructor, suppress copy */
25+
public: auto operator=(quantity const&) -> void = delete;
26+
27+
28+
#line 11 "pure2-bugfix-for-discard-precedence.cpp2"
29+
};
30+
31+
auto main() -> int;
32+
33+
34+
//=== Cpp2 function definitions =================================================
35+
36+
37+
#line 3 "pure2-bugfix-for-discard-precedence.cpp2"
38+
quantity::quantity(cpp2::in<std::in_place_t> _, cpp2::in<cpp2::i32> x)
39+
: number{ x }
40+
#line 3 "pure2-bugfix-for-discard-precedence.cpp2"
41+
{
42+
43+
(void) _;
44+
}
45+
[[nodiscard]] auto quantity::operator+=(quantity const& that) -> quantity&{
46+
(void) 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+
(void) x += std::move(x);
54+
}
55+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-bugfix-for-discard-precedence.cpp2... ok (all Cpp2, passes safety checks)
2+

0 commit comments

Comments
 (0)