Fix alloc empty struct array error

pull/14007/head
chengqinglin 2022-04-11 11:14:55 +08:00
parent 3f90809035
commit 75ff76a999
2 changed files with 10 additions and 6 deletions

View File

@ -300,3 +300,11 @@ fn test_alias_string_contains() {
names := [Str('')]
assert (Str('') in names) == true
}
struct XYZ {}
fn test_array_append_empty_struct() {
mut names := []XYZ{cap: 2}
names << XYZ{}
assert (XYZ{} in names) == true
}

View File

@ -258,7 +258,7 @@ static void __closure_destroy(void *closure) {
const c_common_macros = '
#define EMPTY_VARG_INITIALIZATION 0
#define EMPTY_STRUCT_DECLARATION
#define EMPTY_STRUCT_DECLARATION char _dummy
#define EMPTY_STRUCT_INITIALIZATION
// Due to a tcc bug, the length of an array needs to be specified, but GCC crashes if it is...
#define EMPTY_ARRAY_OF_ELEMS(x,n) (x[])
@ -300,8 +300,6 @@ const c_common_macros = '
#endif
#ifdef __TINYC__
#undef EMPTY_STRUCT_DECLARATION
#define EMPTY_STRUCT_DECLARATION char _dummy
#undef EMPTY_ARRAY_OF_ELEMS
#define EMPTY_ARRAY_OF_ELEMS(x,n) (x[n])
#undef __NOINLINE
@ -576,10 +574,8 @@ voidptr memdup(voidptr src, int sz);
#define _Atomic volatile
// MSVC cannot parse some things properly
#undef EMPTY_STRUCT_DECLARATION
#undef OPTION_CAST
#define EMPTY_STRUCT_DECLARATION char __pad
#define OPTION_CAST(x)
#undef __NOINLINE
#undef __IRQHANDLER