adds support for noDecl in constructor (#22811)

Notice the test wouldnt link before
This commit is contained in:
Juan M Gómez
2023-10-11 07:28:00 +01:00
committed by GitHub
parent 81b2ae747e
commit bf72d87f24
3 changed files with 12 additions and 2 deletions

View File

@@ -757,6 +757,7 @@ proc getRecordFields(m: BModule; typ: PType, check: var IntSet): Rope =
isCtorGen = true
if prc.typ.n.len == 1:
isDefaultCtorGen = true
if lfNoDecl in prc.loc.flags: continue
genMemberProcHeader(m, prc, header, false, true)
result.addf "$1;$n", [header]
if isCtorGen and not isDefaultCtorGen:

View File

@@ -2345,7 +2345,7 @@ proc makeFoo(x: int32): Foo {.constructor.} =
result.x = x
```
It forward declares the constructor in the type definition. When the constructor has parameters, it also generates a default constructor.
It forward declares the constructor in the type definition. When the constructor has parameters, it also generates a default constructor. One can avoid this behaviour by using `noDecl` in a default constructor.
Like `virtual`, `constructor` also supports a syntax that allows to express C++ constraints.

View File

@@ -16,6 +16,7 @@ ___
777
10
123
()
'''
"""
@@ -106,4 +107,12 @@ proc init =
n.x = 123
echo n.x
init()
init()
#tests that the ctor is not declared with nodecl.
#nodelc also prevents the creation of a default one when another is created.
type Foo {.exportc.} = object
proc makeFoo(): Foo {.used, constructor, nodecl.} = discard
echo $Foo()