digitalmars.D - UFCS on forward reference
- John Belmonte (17/17) May 14 2012 C API's often use a opaque struct pointer as a handle. Mapping
- Timon Gehr (3/16) May 14 2012 This is a compiler bug. You can report it here:
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (6/29) May 14 2012 I would expect the compiler to need to see the definition of S to know
- Timon Gehr (2/30) May 15 2012 S is opaque. It does not have any visible member functions.
- Jens Mueller (7/41) May 15 2012 on.
- Timon Gehr (4/43) May 15 2012 This is a compile time error:
- Gor Gyolchanyan (9/51) May 15 2012 It's as simple as not finding a definition of S. I think it's pretty
- John Belmonte (2/31) May 15 2012 Thanks-- filed http://d.puremagic.com/issues/show_bug.cgi?id=8104.
- Gor Gyolchanyan (5/34) May 16 2012 voted up
- John Belmonte (22/22) May 26 2012 Status update:
C API's often use a opaque struct pointer as a handle. Mapping such a struct to D using a forward declaration, I noticed that UFCS doesn't work: struct State; ... State* s = new_state(); foo(s); // ok s.foo(); // compile error Error detail: Error: struct State is forward referenced when looking for 'foo' Error: struct State is forward referenced when looking for 'opDot' Error: struct State is forward referenced when looking for 'opDispatch' I'm wondering if anything would be harmed by removing this restriction. As a workaround I can use "struct State {}", but that feels wrong.
May 14 2012
On 05/15/2012 04:28 AM, John Belmonte wrote:C API's often use a opaque struct pointer as a handle. Mapping such a struct to D using a forward declaration, I noticed that UFCS doesn't work: struct State; ... State* s = new_state(); foo(s); // ok s.foo(); // compile error Error detail: Error: struct State is forward referenced when looking for 'foo' Error: struct State is forward referenced when looking for 'opDot' Error: struct State is forward referenced when looking for 'opDispatch' I'm wondering if anything would be harmed by removing this restriction. As a workaround I can use "struct State {}", but that feels wrong.This is a compiler bug. You can report it here: http://d.puremagic.com/issues/
May 14 2012
On 05/14/2012 10:02 PM, Timon Gehr wrote:On 05/15/2012 04:28 AM, John Belmonte wrote:I would expect the compiler to need to see the definition of S to know that it really does not have a matching foo() member function. Ali -- D Programming Language Tutorial: http://ddili.org/ders/d.en/index.htmlC API's often use a opaque struct pointer as a handle. Mapping such a struct to D using a forward declaration, I noticed that UFCS doesn't work: struct State; ... State* s = new_state(); foo(s); // ok s.foo(); // compile error Error detail: Error: struct State is forward referenced when looking for 'foo' Error: struct State is forward referenced when looking for 'opDot' Error: struct State is forward referenced when looking for 'opDispatch' I'm wondering if anything would be harmed by removing this restriction. As a workaround I can use "struct State {}", but that feels wrong.This is a compiler bug. You can report it here: http://d.puremagic.com/issues/
May 14 2012
On 05/15/2012 07:44 AM, Ali Çehreli wrote:On 05/14/2012 10:02 PM, Timon Gehr wrote: > On 05/15/2012 04:28 AM, John Belmonte wrote: >> C API's often use a opaque struct pointer as a handle. Mapping such a >> struct to D using a forward declaration, I noticed that UFCS doesn't >> work: >> >> struct State; >> ... >> State* s = new_state(); >> foo(s); // ok >> s.foo(); // compile error >> >> Error detail: >> >> Error: struct State is forward referenced when looking for 'foo' >> Error: struct State is forward referenced when looking for 'opDot' >> Error: struct State is forward referenced when looking for 'opDispatch' >> >> I'm wondering if anything would be harmed by removing this restriction. >> >> As a workaround I can use "struct State {}", but that feels wrong. >> > > This is a compiler bug. You can report it here: > http://d.puremagic.com/issues/ I would expect the compiler to need to see the definition of S to know that it really does not have a matching foo() member function. AliS is opaque. It does not have any visible member functions.
May 15 2012
Timon Gehr wrote:On 05/15/2012 07:44 AM, Ali =C7ehreli wrote:ch'On 05/14/2012 10:02 PM, Timon Gehr wrote:On 05/15/2012 04:28 AM, John Belmonte wrote:C API's often use a opaque struct pointer as a handle. Mapping such a struct to D using a forward declaration, I noticed that UFCS doesn't work: struct State; ... State* s =3D new_state(); foo(s); // ok s.foo(); // compile error Error detail: Error: struct State is forward referenced when looking for 'foo' Error: struct State is forward referenced when looking for 'opDot' Error: struct State is forward referenced when looking for 'opDispat=on.I'm wondering if anything would be harmed by removing this restricti=How should the compiler infer that S is opaque? How does it know when you write "struct State;" that State has no members? Is opaqueness implied when I do a forward declaration? Jens=20 S is opaque. It does not have any visible member functions.I would expect the compiler to need to see the definition of S to know that it really does not have a matching foo() member function. AliAs a workaround I can use "struct State {}", but that feels wrong.This is a compiler bug. You can report it here: http://d.puremagic.com/issues/
May 15 2012
On 05/15/2012 11:18 AM, Jens Mueller wrote:Timon Gehr wrote:This is a compile time error: struct S; struct S{}On 05/15/2012 07:44 AM, Ali Çehreli wrote:How should the compiler infer that S is opaque? How does it know when you write "struct State;" that State has no members? Is opaqueness implied when I do a forward declaration? JensOn 05/14/2012 10:02 PM, Timon Gehr wrote:S is opaque. It does not have any visible member functions.On 05/15/2012 04:28 AM, John Belmonte wrote:I would expect the compiler to need to see the definition of S to know that it really does not have a matching foo() member function. AliC API's often use a opaque struct pointer as a handle. Mapping such a struct to D using a forward declaration, I noticed that UFCS doesn't work: struct State; ... State* s = new_state(); foo(s); // ok s.foo(); // compile error Error detail: Error: struct State is forward referenced when looking for 'foo' Error: struct State is forward referenced when looking for 'opDot' Error: struct State is forward referenced when looking for 'opDispatch' I'm wondering if anything would be harmed by removing this restriction. As a workaround I can use "struct State {}", but that feels wrong.This is a compiler bug. You can report it here: http://d.puremagic.com/issues/
May 15 2012
It's as simple as not finding a definition of S. I think it's pretty obvious. On Tue, May 15, 2012 at 1:18 PM, Jens Mueller <jens.k.mueller gmx.de> wrote= :Timon Gehr wrote:hOn 05/15/2012 07:44 AM, Ali =C3=87ehreli wrote:On 05/14/2012 10:02 PM, Timon Gehr wrote:On 05/15/2012 04:28 AM, John Belmonte wrote:C API's often use a opaque struct pointer as a handle. Mapping suc=a'tstruct to D using a forward declaration, I noticed that UFCS doesn=--=20 Bye, Gor Gyolchanyan.'opDispatch'work: struct State; ... State* s =3D new_state(); foo(s); // ok s.foo(); // compile error Error detail: Error: struct State is forward referenced when looking for 'foo' Error: struct State is forward referenced when looking for 'opDot' Error: struct State is forward referenced when looking forrestriction.I'm wondering if anything would be harmed by removing thisHow should the compiler infer that S is opaque? How does it know when you write "struct State;" that State has no members? Is opaqueness implied when I do a forward declaration? JensS is opaque. It does not have any visible member functions.I would expect the compiler to need to see the definition of S to know that it really does not have a matching foo() member function. AliAs a workaround I can use "struct State {}", but that feels wrong.This is a compiler bug. You can report it here: http://d.puremagic.com/issues/
May 15 2012
On Tuesday, 15 May 2012 at 05:02:20 UTC, Timon Gehr wrote:On 05/15/2012 04:28 AM, John Belmonte wrote:Thanks-- filed http://d.puremagic.com/issues/show_bug.cgi?id=8104.C API's often use a opaque struct pointer as a handle. Mapping such a struct to D using a forward declaration, I noticed that UFCS doesn't work: struct State; ... State* s = new_state(); foo(s); // ok s.foo(); // compile error Error detail: Error: struct State is forward referenced when looking for 'foo' Error: struct State is forward referenced when looking for 'opDot' Error: struct State is forward referenced when looking for 'opDispatch' I'm wondering if anything would be harmed by removing this restriction. As a workaround I can use "struct State {}", but that feels wrong.This is a compiler bug. You can report it here: http://d.puremagic.com/issues/
May 15 2012
On Wed, May 16, 2012 at 4:59 AM, John Belmonte <john neggie.net> wrote:On Tuesday, 15 May 2012 at 05:02:20 UTC, Timon Gehr wrote:voted up -- Bye, Gor Gyolchanyan.On 05/15/2012 04:28 AM, John Belmonte wrote:Thanks-- filed http://d.puremagic.com/issues/**show_bug.cgi?id=8104<http://d.puremagic.com/issues/show_bug.cgi?id=8104> .C API's often use a opaque struct pointer as a handle. Mapping such a struct to D using a forward declaration, I noticed that UFCS doesn't work: struct State; ... State* s = new_state(); foo(s); // ok s.foo(); // compile error Error detail: Error: struct State is forward referenced when looking for 'foo' Error: struct State is forward referenced when looking for 'opDot' Error: struct State is forward referenced when looking for 'opDispatch' I'm wondering if anything would be harmed by removing this restriction. As a workaround I can use "struct State {}", but that feels wrong.This is a compiler bug. You can report it here: http://d.puremagic.com/issues/
May 16 2012
Status update: I created a pull request for the trivial change required to allow UFCS on opaque structs. Kenji Hara balked at the change however, on the grounds that it opens up function hijacking. I argued why that is not true-- at least using Walter's original definition of hijacking. No response from Kenji, and things have been at a standstill for a week now. Really this comes down to how we want to define opaque struct in the language specification. The current definition from (http://dlang.org/struct.html): "The members are completely hidden to the user, and so the only operations on those types are ones that do not require any knowledge of the contents of those types." That definition is a bit vague. Do methods count as "contents" of a struct? I propose distinguishing between structural content (fields, types, and sizes) and non-structural content (methods): "Members are completely hidden to the user. Operations which require knowledge of the struct layout are not allowed and yield a compile error. As far as methods, an opaque struct has none-- a property which can be relied on when employing uniform function call syntax." http://d.puremagic.com/issues/show_bug.cgi?id=8104
May 26 2012