Skip to content

Commit 2f730af

Browse files
authored
fix #18410 (Errors initializing an object of RootObj with the C++ backend) [backport] (#18836)
* fix #18410 * one line comment * typo * typo * cover cpp
1 parent 2bda4a3 commit 2f730af

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

compiler/cgen.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ proc genObjectInit(p: BProc, section: TCProcSection, t: PType, a: var TLoc,
363363
else:
364364
linefmt(p, section, "$1.m_type = $2;$n", [r, genTypeInfoV1(p.module, t, a.lode.info)])
365365
of frEmbedded:
366-
if optTinyRtti in p.config.globalOptions:
366+
# inheritance in C++ does not allow struct initialization: bug #18410
367+
if not p.module.compileToCpp and optTinyRtti in p.config.globalOptions:
367368
var tmp: TLoc
368369
if mode == constructRefObj:
369370
let objType = t.skipTypes(abstractInst+{tyRef})

tests/arc/tconst_to_sink.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
discard """
22
output: '''@[(s1: "333", s2: ""), (s1: "abc", s2: "def"), (s1: "3x", s2: ""), (s1: "3x", s2: ""), (s1: "3x", s2: ""), (s1: "3x", s2: ""), (s1: "lastone", s2: "")]'''
3-
cmd: "nim c --gc:arc $file"
3+
matrix: "--gc:arc"
4+
targets: "c cpp"
45
"""
56

67
# bug #13240

tests/cpp/torc.nim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
discard """
2+
targets: "cpp"
3+
matrix: "--gc:orc"
4+
"""
5+
6+
import std/options
7+
8+
# bug #18410
9+
type
10+
O = object of RootObj
11+
val: pointer
12+
13+
proc p(): Option[O] = none(O)
14+
15+
doAssert $p() == "none(O)"

0 commit comments

Comments
 (0)