the following code doesn't compile anymore (git HEAD):
import core.stdc.stdlib;
extern(C) int cmp (const void *a, const void *b) { return 0; }
void main () {
int[4] arr;
qsort(arr.ptr, arr[0].sizeof, arr.length, &cmp);
}
...due to added `scope` in compare function prototype. i think we should not break user's code right away, there should be a deprecation stage first.
Comment #1 by bugzilla — 2017-04-12T04:47:46Z
The trouble is, I'm not sure how to deprecate in a way that still checks for scope.
Comment #2 by r.sagitario — 2017-10-08T13:38:14Z
As qsort is @system anyway, the callback does not have to guarantee anything. To still be able to pass a function with scope parameters, how about overloading it with both variants:
alias int function(scope const void*, scope const void*) _scope_compare_fp_t;
alias int function(const void*, const void*) _compare_fp_t;
void qsort(scope void* base, size_t nmemb, size_t size, _scope_compare_fp_t compar);
void qsort(scope void* base, size_t nmemb, size_t size, _compare_fp_t compar);
Comment #3 by r.sagitario — 2017-10-08T13:50:59Z
The overload with a non-scope callback should also not pretend to not escape the base pointer:
void qsort(void* base, size_t nmemb, size_t size, _compare_fp_t compar);
Comment #4 by greensunny12 — 2017-12-13T09:20:23Z
It's been more than ten months since the bug was report, hence I think that triggering a deprecation message now, would be way too late -> closing.
Comment #5 by r.sagitario — 2017-12-16T13:23:21Z
My suggestion with two overloads would not need a deprecation, but allow both scope and non-scope versions.
Comment #6 by petar.p.kirov — 2017-12-16T14:22:47Z
I agree with Rainer that we should use overloading.
Comment #7 by code — 2018-02-28T18:22:04Z
> As qsort is @system anyway, the callback does not have to guarantee anything. To still be able to pass a function with scope parameters, how about overloading it with both variants
I think we:
- Need to add some sort of wildcard attribute for such cases, as declinating all 16 combinations of `@nogc`, `pure`, `nothrow`, `@safe` callbacks isn't feasible.
- Should simply remove scope in this specific case as the function is @system and scope won't be checked anyhow, overloading with both variants doesn't buy us anything.
Comment #8 by github-bugzilla — 2018-03-02T23:19:28Z