Skip to content

Commit

Permalink
adds a test case (#24469)
Browse files Browse the repository at this point in the history
closes #13945
  • Loading branch information
ringabout authored Nov 23, 2024
1 parent 652edb2 commit af3181e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/misc/tsizeof.nim
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,39 @@ type

doAssert sizeof(ChunkObj) == 1
doAssert offsetOf(ChunkObj, data) == 1


block: # bug #13945
template c_sizeof(T: typedesc): int =
block:
# proc needed pending https://github.com/nim-lang/Nim/issues/13943 D20200409T215527
proc fun2(): int =
{.emit:[result," = sizeof(", T, ");"].}
fun2()

macro test(body: untyped): untyped =
result = newStmtList()
for T in body:
result.add quote do:
let s1 = `T`.sizeof
let s2 = `T`.c_sizeof
doAssert s1 == s2

type FooEmpty = object
const N = 10
type FooEmptyArr = array[N, FooEmpty]
type Bar = object
x: FooEmpty
y: cint

type BarTup = (FooEmpty, cint)
type BarTup2 = (().type, cint)

test:
FooEmpty
FooEmptyArr
Bar
BarTup
BarTup2


0 comments on commit af3181e

Please sign in to comment.