From ff7b83f2662f20e9b34d6a5a6872cba35c06d0fd Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Sat, 23 Nov 2024 20:39:26 +0800 Subject: [PATCH] adds a test case (#24469) closes #13945 (cherry picked from commit af3181e75b55f0246b0c46b9ec23613d3a0c06f4) --- tests/misc/tsizeof.nim | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/misc/tsizeof.nim b/tests/misc/tsizeof.nim index ce53346647..65756bbce7 100644 --- a/tests/misc/tsizeof.nim +++ b/tests/misc/tsizeof.nim @@ -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 + +