mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
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);
};
```
28 lines
429 B
Nim
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)
|
|
|