Bug 6596 – Error message with not extern(C) function

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2011-09-02T10:13:00Z
Last change time
2011-09-25T04:09:12Z
Keywords
diagnostic, patch
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-09-02T10:13:29Z
This is a spin-off of bug 5069 (On request of yebblies too). This is a wrong D2 program: import std.c.stdlib: qsort; import std.c.stdio: printf; int compare(const void *a, const void *b) { return *cast(int*)a - *cast(int*)b; } void main () { int[] values = [40, 10, 100, 90, 20, 25]; for (int n = 0; n < 6; n++) printf ("%d ", values[n]); printf("\n"); qsort(values.ptr, 6, int.sizeof, &compare); for (int n = 0; n < 6; n++) printf ("%d ", values[n]); printf("\n"); } With dmd 2.055head it prints: test.d(11): Error: function core.stdc.stdlib.qsort (void* base, uint nmemb, uint size, int C function(in const(void*), in const(void*)) compar) is not callable using argument types (int*,int,uint,int function(in const(void*), in const(void*))) test.d(11): Error: cannot implicitly convert expression (& compare) of type int function(in const(void*), in const(void*)) to int C function(in const(void*), in const(void*)) I'd like it to print: int extern(C) function(in const(void*), in const(void*)) Instead of: int C function(in const(void*), in const(void*)) Because it's easy to miss a single C in the noise of the error message, and because it's closer to the code that you actually have to write. Even better is to produce a single error message, reducing the clutter: test.d(11): Error: cannot implicitly convert expression (&compare) of type int function(in const(void*), in const(void*)) to int extern(C) function(in const(void*), in const(void*))
Comment #1 by k.hara.pg — 2011-09-22T04:23:56Z
Reduce test case: ---- extern (C) int function() pfunc; extern (C) int cfunc(){ return 0; } // current behavior static assert(typeof(pfunc).stringof == "int C function()"); static assert(typeof(cfunc).stringof == "intC ()"); // expect (1) static assert(typeof(pfunc).stringof == "int extern (C) function()"); static assert(typeof(cfunc).stringof == "int extern (C) ()"); // expect (2) static assert(typeof(pfunc).stringof == "extern (C) int function()"); static assert(typeof(cfunc).stringof == "extern (C) int()"); ---- I think #2 is more better.
Comment #2 by k.hara.pg — 2011-09-22T07:35:46Z
https://github.com/D-Programming-Language/dmd/pull/404 Implements: (In reply to comment #1) > extern (C) int function() pfunc; > extern (C) int cfunc(){ return 0; } > [snip] > > // expect (2) > static assert(typeof(pfunc).stringof == "extern (C) int function()"); > static assert(typeof(cfunc).stringof == "extern (C) int()");
Comment #3 by bugzilla — 2011-09-24T21:03:16Z
Comment #4 by bearophile_hugs — 2011-09-25T04:09:12Z
Thank you. But is "in const(void*)" correct? Aren't "in void*" or "const(void*)" or "const void*" enough?