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.
@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
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