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

C++ backend fails when put inherited object in another object type #17351

Closed
tommo opened this issue Mar 12, 2021 · 1 comment · Fixed by #20407
Closed

C++ backend fails when put inherited object in another object type #17351

tommo opened this issue Mar 12, 2021 · 1 comment · Fixed by #20407

Comments

@tommo
Copy link

tommo commented Mar 12, 2021

See the code below.

Example

type
  Foo {.inheritable.} = object
  Foo2 = object of Foo
  Bar = object
    x: Foo2

var b = Bar()

C backend - OK on both Mac and Windows.
C++ backend on Mac - OK with refc; failed with ORC/ARC, error message:

> nim cpp --gc:orc sss.nim
Hint: used config file '/Users/tommo/.choosenim/toolchains/nim-#devel/config/nim.cfg' [Conf]
Hint: used config file '/Users/tommo/.choosenim/toolchains/nim-#devel/config/config.nims' [Conf]
....
/Volumes/prj/sss.nim(7, 5) Hint: 'b' is declared but not used [XDeclaredButNotUsed]
CC: stdlib_system.nim
CC: sss.nim
/Users/tommo/.cache/nim/sss_d/@msss.nim.cpp:64:81: error: no matching constructor for initialization of
      'tyObject_Foo2__9ahL77ntrZsIwkb3d79aEmnw'
N_LIB_PRIVATE tyObject_Bar__sn3WATLZsEVBvn7zdG4hyg b__p4W8w5cyf34l5eeq3NRwoQ = {{{(&NTIv2__9ahL77ntrZsIwkb3d79aEmnw_)}}}
                                                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/tommo/.cache/nim/sss_d/@msss.nim.cpp:47:8: note: candidate constructor (the implicit copy constructor) not viable: cannot convert
      initializer list argument to 'const tyObject_Foo2__9ahL77ntrZsIwkb3d79aEmnw'
struct tyObject_Foo2__9ahL77ntrZsIwkb3d79aEmnw : public tyObject_Foo__0leyIMOM9a7DLpMIMHk9cOYQ {
       ^
/Users/tommo/.cache/nim/sss_d/@msss.nim.cpp:47:8: note: candidate constructor (the implicit move constructor) not viable: cannot convert
      initializer list argument to 'tyObject_Foo2__9ahL77ntrZsIwkb3d79aEmnw'
struct tyObject_Foo2__9ahL77ntrZsIwkb3d79aEmnw : public tyObject_Foo__0leyIMOM9a7DLpMIMHk9cOYQ {
       ^
/Users/tommo/.cache/nim/sss_d/@msss.nim.cpp:47:8: note: candidate constructor (the implicit default constructor) not viable: requires 0
      arguments, but 1 was provided
1 error generated.
Error: execution of an external compiler program 'clang++ -c -std=gnu++14 -funsigned-char    -I'/Users/tommo/.choosenim/toolchains/nim-#devel/lib' -I/Volumes/prj -o /Users/tommo/.cache/nim/sss_d/@msss.nim.cpp.o /Users/tommo/.cache/nim/sss_d/@msss.nim.cpp' failed with exit code: 1


C++ backend on Windows - Failed, error message:

Hint: used config file 'C:\Users\tommo\.choosenim\toolchains\nim-#devel\config\nim.cfg' [Conf]
Hint: used config file 'C:\Users\tommo\.choosenim\toolchains\nim-#devel\config\config.nims' [Conf]
....
C:\prj\bug.nim(7, 5) Hint: 'b' is declared but not used [XDeclaredButNotUsed]
CC: bug.nim
C:\Users\tommo\nimcache\bug_d\@mbug.nim.cpp:84:121: error: could not convert '{{(& NTI__B6RJJsnBCpiv5jn359b7JyA_)}}' from '<brace-enclosed initializer list>' to 'tyObject_Foo2__B6RJJsnBCpiv5jn359b7JyA'
 N_LIB_PRIVATE tyObject_Bar__9byueIqvoUoAILn9aJtrZh1w b__ybC7cit9bewkcaDkLobKB9ag = {{{(&NTI__B6RJJsnBCpiv5jn359b7JyA_)}}}
                                                                                                                         ^
Error: execution of an external compiler program 'g++.exe -c -std=gnu++14 -funsigned-char  -w -fmax-errors=3 -fpermissive -mno-ms-bitfields   -IC:\Users\tommo\.choosenim\toolchains\nim-#devel\lib -IC:\prj -o C:\Users\tommo\nimcache\bug_d\@mbug.nim.cpp.o C:\Users\tommo\nimcache\bug_d\@mbug.nim.cpp' failed with exit code: 1

Tried with both devel and 1.4.4.

@cooldome
Copy link
Member

I have the fix. gnu++14 needs to be replaces with gnu++17

cooldome added a commit that referenced this issue Mar 14, 2021
@cooldome cooldome mentioned this issue Mar 14, 2021
@tommo tommo closed this as completed Nov 19, 2021
ringabout added a commit that referenced this issue Sep 22, 2022
Araq pushed a commit that referenced this issue Sep 23, 2022
* fix #17351; switch to c++17

* remove workaround
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants