diff options
author | flywind <xzsflywind@gmail.com> | 2021-10-31 13:22:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-31 06:22:00 +0100 |
commit | 2f730afe9e7eb981258aea257deba0240f488dd1 (patch) | |
tree | 6e0adc83014fa80c07a56e5877e80612aa48f731 | |
parent | 2bda4a30a6b12dd0840dc347e454e54fe26721e7 (diff) | |
download | Nim-2f730afe9e7eb981258aea257deba0240f488dd1.tar.gz |
fix #18410 (Errors initializing an object of RootObj with the C++ backend) [backport] (#18836)
* fix #18410 * one line comment * typo * typo * cover cpp
-rw-r--r-- | compiler/cgen.nim | 3 | ||||
-rw-r--r-- | tests/arc/tconst_to_sink.nim | 3 | ||||
-rw-r--r-- | tests/cpp/torc.nim | 15 |
3 files changed, 19 insertions, 2 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 412a428da..b669483cc 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -363,7 +363,8 @@ proc genObjectInit(p: BProc, section: TCProcSection, t: PType, a: var TLoc, else: linefmt(p, section, "$1.m_type = $2;$n", [r, genTypeInfoV1(p.module, t, a.lode.info)]) of frEmbedded: - if optTinyRtti in p.config.globalOptions: + # inheritance in C++ does not allow struct initialization: bug #18410 + if not p.module.compileToCpp and optTinyRtti in p.config.globalOptions: var tmp: TLoc if mode == constructRefObj: let objType = t.skipTypes(abstractInst+{tyRef}) diff --git a/tests/arc/tconst_to_sink.nim b/tests/arc/tconst_to_sink.nim index ddcc46e67..25f659341 100644 --- a/tests/arc/tconst_to_sink.nim +++ b/tests/arc/tconst_to_sink.nim @@ -1,6 +1,7 @@ discard """ output: '''@[(s1: "333", s2: ""), (s1: "abc", s2: "def"), (s1: "3x", s2: ""), (s1: "3x", s2: ""), (s1: "3x", s2: ""), (s1: "3x", s2: ""), (s1: "lastone", s2: "")]''' - cmd: "nim c --gc:arc $file" + matrix: "--gc:arc" + targets: "c cpp" """ # bug #13240 diff --git a/tests/cpp/torc.nim b/tests/cpp/torc.nim new file mode 100644 index 000000000..7fc474f94 --- /dev/null +++ b/tests/cpp/torc.nim @@ -0,0 +1,15 @@ +discard """ + targets: "cpp" + matrix: "--gc:orc" +""" + +import std/options + +# bug #18410 +type + O = object of RootObj + val: pointer + +proc p(): Option[O] = none(O) + +doAssert $p() == "none(O)" \ No newline at end of file |