Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 02f30af

Browse files
committed
fix Issue 17188 - qsort predicate requires scope parameters
- remove scope as it's not checked for `@system` functions anyhow - adding overloads would be an alternative approach, but it's 32 variants to support all of `scope`, `@safe`, `pure`, `nothrow`, `@nogc`
1 parent ce8c251 commit 02f30af

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/core/stdc/stdlib.d

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,24 @@ extern (C):
3232
/* Placed outside @nogc in order to not constrain what the callback does.
3333
*/
3434
///
35-
alias int function(scope const void*, scope const void*) _compare_fp_t;
35+
alias int function(const void*, const void*) _compare_fp_t;
3636
///
37-
inout(void)* bsearch(scope const void* key, scope inout(void)* base, size_t nmemb, size_t size, _compare_fp_t compar);
37+
inout(void)* bsearch(const void* key, inout(void)* base, size_t nmemb, size_t size, _compare_fp_t compar);
3838
///
39-
void qsort(scope void* base, size_t nmemb, size_t size, _compare_fp_t compar);
39+
void qsort(void* base, size_t nmemb, size_t size, _compare_fp_t compar);
4040

41+
// https://issues.dlang.org/show_bug.cgi?id=17188
42+
@system unittest
43+
{
44+
struct S
45+
{
46+
extern(C) static int cmp(const void*, const void*) { return 0; }
47+
}
48+
int[4] arr;
49+
qsort(arr.ptr, arr[0].sizeof, arr.length, &S.cmp);
50+
int key;
51+
bsearch(&key, arr.ptr, arr[0].sizeof, arr.length, &S.cmp);
52+
}
4153

4254
nothrow:
4355
@nogc:

0 commit comments

Comments
 (0)