summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorHexSegfaultCat <167362716+HexSegfaultCat@users.noreply.github.com>2024-04-18 21:57:06 +0200
committerGitHub <noreply@github.com>2024-04-18 21:57:06 +0200
commit558bbb7426b21156b6ad5f8834a62cdf067a2ac3 (patch)
treec991361beb1488b6642a095187d7677fcaa51e80 /compiler
parent229c125d2f66bf983b16b7b56b6e7aeff58f7663 (diff)
downloadNim-558bbb7426b21156b6ad5f8834a62cdf067a2ac3.tar.gz
Fix duplicated member declarations in structs for C++ backend (#23512)
When forward declaration is used with pragmas `virtual` or `member`, the
declaration in struct is added twice. It happens because of missing
check for `sfWasForwarded` pragma.

Current compiler generates the following C++ code:
```cpp
struct tyObject_Foo__fFO9b6HU7kRnKB9aJA1RApKw {
N_LIB_PRIVATE N_NOCONV(void, abc)(NI x_p1);
N_LIB_PRIVATE N_NOCONV(virtual void, def)(NI y_p1);
N_LIB_PRIVATE N_NOCONV(void, abc)(NI x_p1);
N_LIB_PRIVATE N_NOCONV(virtual void, def)(NI y_p1);
};
```
Diffstat (limited to 'compiler')
-rw-r--r--compiler/semstmts.nim2
1 files changed, 1 insertions, 1 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index f71fc9fa0..7ccc29d7e 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -2402,7 +2402,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
   if sfBorrow in s.flags and c.config.cmd notin cmdDocLike:
     result[bodyPos] = c.graph.emptyNode
 
-  if sfCppMember * s.flags != {}:
+  if sfCppMember * s.flags != {} and sfWasForwarded notin s.flags:
     semCppMember(c, s, n)
 
   if n[bodyPos].kind != nkEmpty and sfError notin s.flags: