nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.58k stars 1.47k forks source link

Compilation Failure - empty scalar initializer - Inheritable objects & Atomics [OA]RC on DEVEL #18844

Closed shayanhabibi closed 3 years ago

shayanhabibi commented 3 years ago

The following fails to compile with the listed error using ARC or ORC however compiles successfully on REFC

import atomics

type
  # Deprivation* = ref object of RootObj    # compiles
  Deprivation* = object of RootObj        # fails
    memes*: Atomic[int]
  Zoomer = object
    dopamine: Deprivation                 # fails
    # dopamine: ref Deprivation             # compiles

# discard Deprivation()                     # compiles
discard Zoomer()                          # fails

I have tagged which lines I have narrowed down to causing issues and what doesn't.

This was found while trying to use elijahrs lockfreequeue types as fields of objects.

C:\Users\PC\nimcache\cpsloop_r\@mcpsloop.nim.c:199:132: error: empty scalar initializer
 static NIM_CONST tyObject_Zoomer__yhOZMQHEaznD9aq8IQHJaMQ TM__8CKjD9bWE6mTvTNPLW3KYWw_2 = {{{(&NTIv2__DdWjNMQNgJ9aHiVjMo4gjYw_)}, {{}}}}

                        ^
C:\Users\PC\nimcache\cpsloop_r\@mcpsloop.nim.c:199:132: note: (near initialization for 'TM__8CKjD9bWE6mTvTNPLW3KYWw_2.dopamine.memes.value')
Error: execution of an external compiler program 'gcc.exe -c  -w -fmax-errors=3 -mno-ms-bitfields -O3 -fno-strict-aliasing -fno-ident   -IC:\Users\PC\.choosenim\toolchains\nim-#devel\lib -Ic:\Users\PC\Documents\Programming\ParthianProject\Modules\cps_minfosclient\cpsbridge -o C:\Users\PC\nimcache\cpsloop_r\@mcpsloop.nim.c.o C:\Users\PC\nimcache\cpsloop_r\@mcpsloop.nim.c' failed with exit code: 1
ringabout commented 3 years ago

Related: https://github.com/nim-lang/Nim/issues/18410

C++ backend can be fixed using -std=gnu++17

I'll push a fix after https://github.com/nim-lang/Nim/pull/18836 is merged or solved.

metagn commented 1 year ago

This is not fixed, or at least it's not tested (this test also does not run for c++ at all). -std=gnu++17 does not seem to fix it.