status-im / nim-stew

stew is collection of utilities, std library extensions and budding libraries that are frequently used at Status, but are too small to deserve their own git repository.
139 stars 18 forks source link

ensure `isZeroMemory` used only on types without tuple/object padding #162

Closed tersec closed 1 year ago

tersec commented 1 year ago

Otherwise, isZeroMemory won't necessarily correspond to the Nim notion of being a default-initialized object of that type.

zah commented 1 year ago

Using typetraits.supportsCopyMem is probably the right way to solve this.

tersec commented 1 year ago

Using typetraits.supportsCopyMem is probably the right way to solve this.

Well, maybe supportsEqualMem: https://github.com/nim-lang/Nim/issues/19897

tersec commented 1 year ago

That doesn't exist, though, so the intent is to at least flag obviously-incorrect usages.