Open
Description
Seems like C++ atomics don't like me at all.
When trying to workaround #13062
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)))
# Bad codegen
pledge.p[] = deref(PledgePtr)(kind: Iteration)
main()
Error
..../.cache/nim/atombug_d/@matombug.nim.cpp: In function ‘void main__b3r7EXSeAzsO9aIDCMEJ8CA()’:
..../.cache/nim/atombug_d/@matombug.nim.cpp:157:16: error: use of deleted function ‘tyObject_PledgePtrcolonObjectType___FkbYobdvoyzypSol0uBgbw& tyObject_PledgePtrcolonObjectType___FkbYobdvoyzypSol0uBgbw::operator=(const tyObject_PledgePtrcolonObjectType___FkbYobdvoyzypSol0uBgbw&)’
157 | (*pledge.p) = T1_;
| ^~~
..../.cache/nim/atombug_d/@matombug.nim.cpp:47:8: note: ‘tyObject_PledgePtrcolonObjectType___FkbYobdvoyzypSol0uBgbw& tyObject_PledgePtrcolonObjectType___FkbYobdvoyzypSol0uBgbw::operator=(const tyObject_PledgePtrcolonObjectType___FkbYobdvoyzypSol0uBgbw&)’ is implicitly deleted because the default definition would be ill-formed:
47 | struct tyObject_PledgePtrcolonObjectType___FkbYobdvoyzypSol0uBgbw {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
..../.cache/nim/atombug_d/@matombug.nim.cpp:47:8: error: use of deleted function ‘std::atomic<int>& std::atomic<int>::operator=(const std::atomic<int>&)’
In file included from ..../.cache/nim/atombug_d/@matombug.nim.cpp:11:
/usr/include/c++/9.2.0/atomic:756:15: note: declared here
756 | atomic& operator=(const atomic&) = delete;
| ^~~~~~~~
..../.cache/nim/atombug_d/@matombug.nim.cpp:47:8: error: use of deleted function ‘tyObject_PledgeImpl__PC08ohoFN4aei4c6kCPnAw& tyObject_PledgeImpl__PC08ohoFN4aei4c6kCPnAw::operator=(const tyObject_PledgeImpl__PC08ohoFN4aei4c6kCPnAw&)’
47 | struct tyObject_PledgePtrcolonObjectType___FkbYobdvoyzypSol0uBgbw {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
..../.cache/nim/atombug_d/@matombug.nim.cpp:43:8: note: ‘tyObject_PledgeImpl__PC08ohoFN4aei4c6kCPnAw& tyObject_PledgeImpl__PC08ohoFN4aei4c6kCPnAw::operator=(const tyObject_PledgeImpl__PC08ohoFN4aei4c6kCPnAw&)’ is implicitly deleted because the default definition would be ill-formed:
43 | struct tyObject_PledgeImpl__PC08ohoFN4aei4c6kCPnAw {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
..../.cache/nim/atombug_d/@matombug.nim.cpp:43:8: error: use of deleted function ‘std::atomic<bool>& std::atomic<bool>::operator=(const std::atomic<bool>&)’
In file included from ..../.cache/nim/atombug_d/@matombug.nim.cpp:11:
/usr/include/c++/9.2.0/atomic:74:13: note: declared here
74 | atomic& operator=(const atomic&) = delete;
| ^~~~~~~~