mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fixes to bitstruct and work on correct behaviour when embedded in structs.
This commit is contained in:
committed by
Christoffer Lerno
parent
4f09b0c351
commit
4e47f0b624
63
test/test_suite/bitstruct/bitstruct_init.c3
Normal file
63
test/test_suite/bitstruct/bitstruct_init.c3
Normal file
@@ -0,0 +1,63 @@
|
||||
// #target
|
||||
module foo;
|
||||
|
||||
bitstruct Foo : uint
|
||||
{
|
||||
int x : 1..3;
|
||||
uint y : 11..13;
|
||||
int z : 15..15;
|
||||
}
|
||||
|
||||
struct Bar
|
||||
{
|
||||
int x;
|
||||
bitstruct baz : int
|
||||
{
|
||||
int x : 1..3;
|
||||
}
|
||||
}
|
||||
|
||||
struct Bar2
|
||||
{
|
||||
int x;
|
||||
bitstruct : int
|
||||
{
|
||||
int z : 1..3;
|
||||
}
|
||||
|
||||
}
|
||||
fn void testNested()
|
||||
{
|
||||
Bar b1 = { 3, { 3 } };
|
||||
Bar b2 = { .x = 3, .baz.x = 3 };
|
||||
Bar2 b3 = { 1, 3 };
|
||||
Bar2 b4 = { .x = 123, .z = 3 };
|
||||
Bar2 b5 = { .x = 123, .z = 4 }; // #error: would be truncated
|
||||
Bar2 b6 = { 1, 3 }; // #error: would be truncated
|
||||
Bar b7 = { 3, { 4 } }; // #error: would be truncated
|
||||
Bar b8 = { .x = 3, .baz.x = 4 }; // #error: would be truncated
|
||||
|
||||
}
|
||||
|
||||
fn void test()
|
||||
{
|
||||
Foo abc = {};
|
||||
abc.x = -4;
|
||||
abc.z = 0;
|
||||
abc.z = -1;
|
||||
abc.x = 3;
|
||||
abc.y = 7;
|
||||
abc.x = -5; // #error: would be truncated
|
||||
abc.x = 4; // #error: would be truncated
|
||||
abc.y = 8; // #error: would be truncated
|
||||
}
|
||||
|
||||
fn void test2()
|
||||
{
|
||||
Foo abc = { -4, 8, 0 }; // #error: would be truncated
|
||||
}
|
||||
|
||||
fn void test3()
|
||||
{
|
||||
Foo abc = { .x = -4, .z = 0, .y = 8 }; // #error: would be truncated
|
||||
}
|
||||
Reference in New Issue
Block a user