www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21631] New: core.atomic.cas fails to compile with const


          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 puremagic.com
          Reporter: htvennik 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.

Feb 12 2021