Files
Nim/tests/cpp/tmember_forward_declaration.nim
HexSegfaultCat 558bbb7426 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);
};
```
2024-04-18 21:57:06 +02:00

28 lines
429 B
Nim

discard """
targets: "cpp"
cmd: "nim cpp $file"
output: '''
abc called
def called
abc called
'''
"""
type Foo = object
proc abc(this: Foo, x: int): void {.member: "$1('2 #2)".}
proc def(this: Foo, y: int): void {.virtual: "$1('2 #2)".}
proc abc(this: Foo, x: int): void =
echo "abc called"
if x > 0:
this.def(x - 1)
proc def(this: Foo, y: int): void =
echo "def called"
this.abc(y)
var x = Foo()
x.abc(1)