www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6596] New: Error message with not extern(C) function

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6596

           Summary: Error message with not extern(C) function
           Product: D
           Version: D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2011-09-02 10:13:29 PDT ---
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*))

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 02 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6596



--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2011-09-22 04:23:56 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 22 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6596


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2011-09-22 07:35:46 PDT ---
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()");
-- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 22 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6596


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


--- Comment #3 from Walter Bright <bugzilla digitalmars.com> 2011-09-24
21:03:16 PDT ---
https://github.com/D-Programming-Language/dmd/commit/15f54382fb89671c1c640d8b7c11da3b3b923aa1

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 24 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6596



--- Comment #4 from bearophile_hugs eml.cc 2011-09-25 04:09:12 PDT ---
Thank you.

But is "in const(void*)" correct?
Aren't "in void*" or "const(void*)" or "const void*" enough?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 25 2011