-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C++ Atomics: operator= is implicitly deleted because the default definition would be ill-formed #13093
Comments
Even this very minimal example doesn't compile for some reason 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()
pledge.p[] = tmp
main() Note that I have plenty of code with atomics that does compile in C++ mode |
To answer the small example, this is actually not allowed 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() The code generated is N_LIB_PRIVATE N_NIMCALL(void, main__BTA1O9bZ9cw3phtcEzYReOQw)(void) {
tyObject_Pledge__liVKkHLjQBejXUzfhcSWAw pledge;
tyObject_PledgeObj__JS8Q9a9bu0tSuejYr9a1kzS1A T1_;
nimZeroMem((void*)(&pledge), sizeof(tyObject_Pledge__liVKkHLjQBejXUzfhcSWAw));
pledge.p = createShared__w7DYWNtNZpqDzb9bgOkT5tAsystem(((NI) 1));
nimZeroMem((void*)(&T1_), sizeof(tyObject_PledgeObj__JS8Q9a9bu0tSuejYr9a1kzS1A));
tyObject_PledgeObj__JS8Q9a9bu0tSuejYr9a1kzS1A tmp = T1_;
(*pledge.p) = tmp;
} and In the past, due to the use of case objects and the fact that we can't change case this is required for but the case-object transition rules seem to have been relaxed so now this seems to be a valid workaround? import atomics
type
Pledge* = object
p: PledgePtr
PledgeKind = enum
Single
Iteration
PledgePtr = ptr object
refCount: Atomic[int32]
impl: PledgeImpl
# The case object is not important for the bug
# but the non-binary 0 case requires the object constructor-based
# initialization as we can't change the case object once constructed
case kind: PledgeKind
of Single:
discard
of Iteration:
discard
PledgeImpl = object
fulfilled: Atomic[bool]
template deref*(T: typedesc): typedesc =
## Return the base object type behind a ptr type
typeof(default(T)[])
proc main() =
var pledge: Pledge
pledge.p = createShared(deref(PledgePtr))
zeroMem(pledge.p, sizeof(deref(PledgePtr)))
# Case object transition avoids invalid copy/sink
pledge.p.kind = Iteration
main() |
…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
…ed because the default definition would be ill-formed " (nim-lang#21307) Revert "Fix nim-lang#13093 C++ Atomics: operator= is implicitly deleted because the default definition would be ill-formed (nim-lang#21169)" This reverts commit a7bae91.
…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
…ed because the default definition would be ill-formed " (nim-lang#21307) Revert "Fix nim-lang#13093 C++ Atomics: operator= is implicitly deleted because the default definition would be ill-formed (nim-lang#21169)" This reverts commit a7bae91.
…se the default definition would be ill-formed
…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
…ed because the default definition would be ill-formed " (nim-lang#21307) Revert "Fix nim-lang#13093 C++ Atomics: operator= is implicitly deleted because the default definition would be ill-formed (nim-lang#21169)" This reverts commit a7bae91.
Seems like C++ atomics don't like me at all.
When trying to workaround #13062
Error
The text was updated successfully, but these errors were encountered: