Summary: Make pointers dereference with UFCS like they do with
                    member functions
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from Jonathan M Davis <> 2012-09-03 19:41:58 
PDT ---
As discussed here

pointers to structs and UFCS don't get along all that well at this point. UFCS
dictates that the first function parameter be the type that the function is
being called on, which means that for UFCS to work with a pointer, the function
must take a pointer.

struct S
    auto func(int i) {...}

auto foo(S* s, int i) { ... }
auto bar(S s, int i) { ... }

S* s;; //compiles; //doesn't compile
(*s).bar(8); //compiles

The problem with this is that while it's consistent with UFCS in general, it's
inconsistent with how member functions get called on pointers to structs.

You can do

S* s;

as long as func is a member function, but if it's a free function, that only
works if the free function takes an S* rather than an S. So, while calling a
member function on a struct is the same whether you're dealing with a pointer
or not

S* s;
S t;

it's different when dealing with a free function and UFCS.

S* s;
S t;

What this enhancement request proposes is that functions which take the struct
as their first parameter rather than a pointer to the struct be considered in
UFCS for pointers to that struct as long as there's no ambiguity. So, you could

S* s;
S t;;;

even though bar takes an S, not an S*. Presumably, if there's a conflict

auto fiddly(S* s, float f) {...}
auto fiddly(S s, float f) {...}

S* s;
S t;; //fails to compile due to ambiguity; //presumably compiles, since it would never use the S* version.

then you'll get a compilation error, but as long as there isn't one, allowing
for an S* to be used with UFCS just like S is would be useful and make it so
that UFCS works with pointers to structs like member functions work with
pointers to structs, which is the main reason for UFCS in the first place.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to