[Issue 21631] New: core.atomic.cas fails to compile with const ifThis (if target is a pointer)
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Feb 12 12:36:47 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=21631
Issue ID: 21631
Summary: core.atomic.cas fails to compile with const ifThis (if
target is a pointer)
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: druntime
Assignee: nobody at puremagic.com
Reporter: htvennik at gmail.com
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.
--
More information about the Digitalmars-d-bugs
mailing list