Bug 21631 – core.atomic.cas fails to compile with const ifThis (if target is a pointer)

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-02-12T12:36:47Z
Last change time
2022-03-28T12:09:26Z
Keywords
pull
Assigned to
No Owner
Creator
Harry Vennik

Comments

Comment #0 by htvennik — 2021-02-12T12:36:47Z
The following snippet fails to compile: ----- shared uint si1 = 45; shared uint si2 = 38; shared uint* psi = &si1; assert((&psi).cas(cast(const) psi, &si2)); ----- Error message: src/core/atomic.d(295): Error: cannot implicitly convert expression ifThis of type shared(const(uint))* to shared(uint)* The cas function has multiple overloads, some of which take a pointer to the ifThis, and use that to store the original value found in the target location of the cas operation. In such case, it's obvious the ifThis cannot be const. But the overloads that simply take ifThis by value (like the one used in the snippet above), cannot change ifThis, and thus should allow it to be const. However, currently this does not work in the case the target type is a pointer to mutable data (or a struct containing such pointer) and ifThis is const.
Comment #1 by dlang-bot — 2021-02-12T12:44:32Z
@thaven created dlang/druntime pull request #3373 "core.atomic.cas: add 'const' attribute to local variable 'arg1'" fixing this issue: - Fix Issue 21631 - cas: add 'const' attribute to local variable 'arg1' https://github.com/dlang/druntime/pull/3373
Comment #2 by dlang-bot — 2022-03-28T12:09:26Z
dlang/druntime pull request #3373 "core.atomic.cas: add 'const' attribute to local variable 'arg1'" was merged into master: - b46844a30b751e6abd5eef59d60f99d5ca3844aa by Harry T. Vennik: Fix Issue 21631 - cas: add 'const' attribute to local variable 'arg1' https://github.com/dlang/druntime/pull/3373