[Issue 10960] Copying a const value type should yield unqual

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 19 05:01:28 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=10960

Mathias LANG <pro.mathias.lang at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pro.mathias.lang at gmail.com

--- Comment #3 from Mathias LANG <pro.mathias.lang at gmail.com> ---
Nowadays this code yields:
```
/usr/local/opt/dmd/include/dlang/dmd/std/algorithm/sorting.d(2934): Error:
function core.stdc.stdlib.free(void* ptr) is not callable using argument types
(const(int)*)
/usr/local/opt/dmd/include/dlang/dmd/std/algorithm/sorting.d(2934):       
cannot pass argument cast(const(int)*)p of type const(int)* to parameter void*
ptr
/usr/local/opt/dmd/include/dlang/dmd/std/algorithm/sorting.d(2952): Error:
template std.algorithm.sorting.sort cannot deduce function from argument types
!((a, b) => binaryFun!less(a[0], b[0]),
cast(SwapStrategy)0)(ZipShortest!(cast(Flag)true, const(int)[], int[])),
candidates are:
/usr/local/opt/dmd/include/dlang/dmd/std/algorithm/sorting.d(1847):       
std.algorithm.sorting.sort(alias less = "a < b", SwapStrategy ss =
SwapStrategy.unstable, Range)(Range r) if ((ss == SwapStrategy.unstable &&
(hasSwappableElements!Range || hasAssignableElements!Range) || ss !=
SwapStrategy.unstable && hasAssignableElements!Range) &&
isRandomAccessRange!Range && hasSlicing!Range && hasLength!Range)
test.d(6): Error: template instance `test.main.schwartzSort!((i) => B[i], "a <
b", cast(SwapStrategy)0, int[])` error instantiating
```

However, I don't think that's a DMD bug. If the implementer of the function
wants to provide a more sensible interface, it's up to them, but the compiler
should not magically remove one level of constness because of this.

--


More information about the Digitalmars-d-bugs mailing list