cgen: fix sizeof('str') and sizeof(r'str') (#14507)

yuyi 2022-05-24 10:14:38 +08:00 committed by Jef Roosens
parent 73e421cd95
commit b717ef74f8
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 8 additions and 5 deletions

View File

@ -5450,12 +5450,14 @@ fn (mut g Gen) size_of(node ast.SizeOf) {
g.error('unknown type `$sym.name`', node.pos)
}
if node.expr is ast.StringLiteral {
if node.expr.language == .c {
g.write('sizeof("$node.expr.val")')
} else {
return
}
}
styp := g.typ(node_typ)
g.write('sizeof(${util.no_dots(styp)})')
}
}
fn (mut g Gen) enum_val(node ast.EnumVal) {
// g.write('${it.mod}${it.enum_name}_$it.val')

View File

@ -25,5 +25,6 @@ fn test_sizeof() {
assert sizeof(flag.Flag) > 4
assert sizeof(c'hello') == 6
assert sizeof(r'hello') == 6
assert sizeof(r'hello') == 16
assert sizeof('hello') == 16
}