[Issue 11312] New: Avoid auto-dereference for UFCS functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Oct 21 03:10:06 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=11312

           Summary: Avoid auto-dereference for UFCS functions
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-10-21 03:10:05 PDT ---
Here's an example of UFCS with a simple int*:

-----
int* getPtr() { return null; }
int getValue(int*) { return 0; }

void main()
{
    int* op = getPtr();
    int x = op.getValue();  // works ok
}
-----

Now the following is an example of where you're interfacing with some C code,
and you want to allow UFCS-style syntax to make it easier to use the C library.
The C library defines opaque struct types and only allows manipulation through
pointers and functions:

-----
struct Struct;
extern(C) Struct* getStruct() { return null; }
extern(C) int getValue(Struct*) { return 0; }

void main()
{
    Struct* op = getStruct();
    int x = op.getValue();  // error
}
-----

This errors with:
test.d(10): Error: struct Struct is forward referenced

I think this might just be a compiler bug. There's no point in dereferencing
the pointer here because the function call would not match (getValue is typed
as Struct*, not Struct).

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


More information about the Digitalmars-d-bugs mailing list