diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/misc/tsizeof.nim | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/tests/misc/tsizeof.nim b/tests/misc/tsizeof.nim index 9cbe9aeb0..a4633021b 100644 --- a/tests/misc/tsizeof.nim +++ b/tests/misc/tsizeof.nim @@ -1,4 +1,5 @@ discard """ + targets: "c cpp" output: ''' body executed body executed @@ -7,6 +8,14 @@ macros api OK ''' """ +# This is for travis. The keyword ``alignof`` only exists in ``c++11`` +# and newer. On travis gcc does not default to c++11 yet. +when defined(cpp) and not defined(windows): + {.passC: "-std=c++11".} + +# Object offsets are different for inheritance objects when compiling +# to c++. + type TMyEnum = enum tmOne, tmTwo, tmThree, tmFour @@ -143,6 +152,14 @@ type ValueA ValueB + # Must have more than 32 elements so that set[MyEnum33] will become compile to an int64. + MyEnum33 {.pure.} = enum + Value1, Value2, Value3, Value4, Value5, Value6, + Value7, Value8, Value9, Value10, Value11, Value12, + Value13, Value14, Value15, Value16, Value17, Value18, + Value19, Value20, Value21, Value22, Value23, Value24, + Value25, Value26, Value27, Value28, Value29, Value30, + Value31, Value32, Value33 proc transformObjectconfigPacked(arg: NimNode): NimNode = let debug = arg.kind == nnkPragmaExpr @@ -296,6 +313,10 @@ testinstance: b: int8 c: int8 + PaddingOfSetEnum33 = object + cause: int8 + theSet: set[MyEnum33] + Bazing {.objectconfig.} = object of RootObj a: int64 # TODO test on 32 bit system @@ -328,6 +349,7 @@ testinstance: var g : RecursiveStuff var ro : RootObj var go : GenericObject[int64] + var po : PaddingOfSetEnum33 var e1: Enum1 @@ -346,16 +368,16 @@ testinstance: else: doAssert sizeof(SimpleAlignment) > 10 - testSizeAlignOf(t,a,b,c,d,e,f,g,ro,go, e1, e2, e4, e8, eoa, eob) + testSizeAlignOf(t,a,b,c,d,e,f,g,ro,go,po, e1, e2, e4, e8, eoa, eob) - when not defined(cpp): - type - WithBitsize {.objectconfig.} = object - bitfieldA {.bitsize: 16.}: uint32 - bitfieldB {.bitsize: 16.}: uint32 - var wbs: WithBitsize - testSize(wbs) + type + WithBitsize {.objectconfig.} = object + bitfieldA {.bitsize: 16.}: uint32 + bitfieldB {.bitsize: 16.}: uint32 + + var wbs: WithBitsize + testSize(wbs) testOffsetOf(TrivialType, x) testOffsetOf(TrivialType, y) @@ -383,11 +405,13 @@ testinstance: testOffsetOf(Foobar, c) - when not defined(cpp): - testOffsetOf(Bazing, a) - testOffsetOf(InheritanceA, a) - testOffsetOf(InheritanceB, b) - testOffsetOf(InheritanceC, c) + testOffsetOf(PaddingOfSetEnum33, cause) + testOffsetOf(PaddingOfSetEnum33, theSet) + + testOffsetOf(Bazing, a) + testOffsetOf(InheritanceA, a) + testOffsetOf(InheritanceB, b) + testOffsetOf(InheritanceC, c) testOffsetOf(EnumObjectA, a) testOffsetOf(EnumObjectA, b) @@ -620,9 +644,6 @@ doAssert offsetof(MyPackedCaseObject, val4) == 9 doAssert offsetof(MyPackedCaseObject, val5) == 13 reject: - const off4 = offsetof(MyPackedCaseObject, val1) - -reject: const off5 = offsetof(MyPackedCaseObject, val2) reject: |