mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: Fix undefined behaviour when allocating empty structs (#4088)
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
struct A{
|
||||
struct A {
|
||||
mut:
|
||||
val int
|
||||
nums []int
|
||||
}
|
||||
|
||||
struct B{
|
||||
struct B {
|
||||
mut:
|
||||
a A
|
||||
}
|
||||
@ -26,6 +26,9 @@ struct Foo {
|
||||
@type string
|
||||
}
|
||||
|
||||
struct Empty {
|
||||
}
|
||||
|
||||
//We need to make sure that this compiles with all the reserved names.
|
||||
struct ReservedKeywords {
|
||||
delete int
|
||||
@ -55,6 +58,12 @@ struct ReservedKeywords {
|
||||
while int
|
||||
}
|
||||
|
||||
fn test_empty_struct() {
|
||||
d := &Empty{}
|
||||
println(d) // != voidptr(0)
|
||||
println(sizeof(Empty)) // == 0
|
||||
}
|
||||
|
||||
fn test_struct_levels() {
|
||||
mut c := C{}
|
||||
assert c.nums.len == 0
|
||||
|
Reference in New Issue
Block a user