Skip to content

Commit f4a2ddb

Browse files
committed
Give @union accessor function the nice name
And fix `@union` alignment
1 parent d9656a0 commit f4a2ddb

17 files changed

+158
-180
lines changed

include/cpp2util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ using in =
569569
//
570570
template<typename T>
571571
class deferred_init {
572-
alignas(T) std::byte data[sizeof(T)]; // or: std::aligned_storage_t<sizeof(T), alignof(T)> data
572+
alignas(T) std::byte data[sizeof(T)];
573573
bool init = false;
574574

575575
auto t() -> T& { return *std::launder(reinterpret_cast<T*>(&data)); }

regression-tests/pure2-enum.cpp2

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,13 @@ skat_game: @enum type = {
88
null := 23;
99
}
1010

11-
duality: @enum type = {
12-
first;
13-
second;
14-
15-
flip: (inout this, val: duality) = {
16-
if val == first {
17-
value__ = second.value__;
18-
}
19-
else {
20-
[[assert: value__ == second.value__]]
21-
value__ = first.value__;
22-
}
11+
janus: @enum type = {
12+
past;
13+
future;
14+
15+
flip: (inout this) = {
16+
if this == past { this = future; }
17+
else { this = past; }
2318
}
2419
}
2520

@@ -31,10 +26,9 @@ file_attributes: @flag_enum<u8> type = {
3126
}
3227

3328
main: () = {
34-
janus := duality::second;
35-
std::cout << "janus is initially (janus.to_string())$\n";
36-
janus.flip( janus );
37-
std::cout << "janus is flipped to (janus.to_string())$\n";
29+
j := janus::past;
30+
j.flip();
31+
_ = j;
3832

3933
// x : skat_game = 9; // error, can't construct skat_game from integer
4034

regression-tests/pure2-union.cpp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name_or_number: @union type = {
66

77
print_name: (non: name_or_number) = {
88
if non.is_name() {
9-
std::cout << non.get_name() << "\n";
9+
std::cout << non.name() << "\n";
1010
}
1111
else {
1212
std::cout << "(not a name)\n";

regression-tests/test-results/clang-12/pure2-enum.cpp.execution

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
janus is initially second
2-
janus is flipped to first
31
x.to_string() is clubs
42
x2.to_string() is clubs
53
using << prints clubs
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
sizeof(x) is 33
1+
sizeof(x) is 48
22
(not a name)
33
xyz

regression-tests/test-results/gcc-10/pure2-enum.cpp.execution

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
janus is initially second
2-
janus is flipped to first
31
x.to_string() is clubs
42
x2.to_string() is clubs
53
using << prints clubs
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
sizeof(x) is 33
1+
sizeof(x) is 48
22
(not a name)
33
xyz

regression-tests/test-results/gcc-13/pure2-enum.cpp.execution

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
janus is initially second
2-
janus is flipped to first
31
x.to_string() is clubs
42
x2.to_string() is clubs
53
using << prints clubs
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
sizeof(x) is 33
1+
sizeof(x) is 48
22
(not a name)
33
xyz

regression-tests/test-results/msvc-2022/pure2-enum.cpp.execution

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
janus is initially second
2-
janus is flipped to first
31
x.to_string() is clubs
42
x2.to_string() is clubs
53
using << prints clubs

0 commit comments

Comments
 (0)