Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds a test case #24469

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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