sizeof for empty objects/tuples should be 1; fixes #14690 (#14751)

This commit is contained in:
Andreas Rumpf 2020-06-21 19:58:37 +02:00 • committed by GitHub
commit 3ba0c30758
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -78,7 +78,7 @@ macro c_offsetof(fieldAccess: typed): int32 =
## Bullet proof implementation that works on actual offsetof operator
## in the c backend. Assuming of course this implementation is
## correct.
let s = if fieldAccess.kind == nnkCheckedFieldExpr: fieldAccess[0]
let s = if fieldAccess.kind == nnkCheckedFieldExpr: fieldAccess[0]
else: fieldAccess
let a = s[0].getTypeInst
let b = s[1]
@ -686,3 +686,11 @@ reject:
reject:
const off8 = offsetof(MyPackedCaseObject, val5)
type
O0 = object
T0 = tuple[]
doAssert sizeof(O0) == 1
doAssert sizeof(T0) == 1