cgen: fix sizeof('str') and sizeof(r'str') (#14507)
parent
73e421cd95
commit
b717ef74f8
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue