forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix nim-lang#13093 C++ Atomics: operator= is implicitly deleted becau…
…se the default definition would be ill-formed (nim-lang#21169) * add test * fix nim-lang#17982 Invalid C++ code generation when returning discardable var T * fix nim-lang#13093 * cpp atomic good example * clearify the condition
- Loading branch information
Showing
5 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
discard """ | ||
targets: "cpp" | ||
action: reject | ||
errormsg: "The PledgeObj type requires the following fields to be initialized: refCount" | ||
""" | ||
|
||
import atomics | ||
|
||
type | ||
Pledge* = object | ||
p: PledgePtr | ||
|
||
PledgePtr = ptr PledgeObj | ||
PledgeObj = object | ||
refCount: Atomic[int32] | ||
|
||
proc main() = | ||
var pledge: Pledge | ||
pledge.p = createShared(PledgeObj) | ||
let tmp = PledgeObj() # <---- not allowed: atomics are not copyable | ||
|
||
pledge.p[] = tmp | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
discard """ | ||
targets: "cpp" | ||
action: "compile" | ||
""" | ||
|
||
type | ||
String* {.importcpp: "std::string", header: "string".} = object | ||
|
||
proc initString*(): String | ||
{.importcpp: "std::string()", header: "string".} | ||
|
||
proc append*(this: var String, str: String): String | ||
# bug seems to trigger when `#`, `@`, or `$1` is used inside `importcpp` | ||
{.importcpp: "#.append(@)", header: "string", discardable.} # <- changed from `importcpp: "append"` | ||
|
||
var | ||
s1 = initString() | ||
s2 = initString() | ||
|
||
s1.append s2 |