diff options
-rw-r--r-- | compiler/ccgtypes.nim | 1 | ||||
-rw-r--r-- | doc/manual_experimental.md | 2 | ||||
-rw-r--r-- | tests/cpp/tconstructor.nim | 11 |
3 files changed, 12 insertions, 2 deletions
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index a5555048f..2f92cb12b 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -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: diff --git a/doc/manual_experimental.md b/doc/manual_experimental.md index 249f9367b..4bafd408f 100644 --- a/doc/manual_experimental.md +++ b/doc/manual_experimental.md @@ -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. diff --git a/tests/cpp/tconstructor.nim b/tests/cpp/tconstructor.nim index 8c5d4dca2..ac73b78e6 100644 --- a/tests/cpp/tconstructor.nim +++ b/tests/cpp/tconstructor.nim @@ -16,6 +16,7 @@ ___ 777 10 123 +() ''' """ @@ -106,4 +107,12 @@ proc init = n.x = 123 echo n.x -init() \ No newline at end of file +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() \ No newline at end of file |