D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10451 - Array of pointers to opaque struct gives forward reference errors.
Summary: Array of pointers to opaque struct gives forward reference errors.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords: pull
: 9795 10766 (view as issue list)
Depends on:
Blocks:
 
Reported: 2013-06-23 08:42 UTC by Mike Parker
Modified: 2013-10-02 05:56 UTC (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Mike Parker 2013-06-23 08:42:23 UTC
struct foo;

struct bar {
    foo*[] foos;
}

The error only occurs when the array is declared as a struct field. When declared as a class member or in a function, there is no error.
Comment 1 Mike Parker 2013-08-11 07:23:09 UTC
I've got some new info on this. The error also occurs outside of structs if the array is initialized:

=========
struct foo;

void main() {
    foo*[] foos = [];
}
=========

Here's the full error spew that I get in both cases:

==================
forref.d(3): Error: struct forrref.foo is forward referenced when looking for 't
oHash'
forref.d(3): Error: struct forrref.foo is forward referenced when looking for 'o
pCmp'
forref.d(3): Error: struct forrref.foo is forward referenced when looking for 't
oString'
forref.d(3): Error: struct forrref.foo unknown size
forref.d(3): Error: struct forrref.foo no size yet for forward reference
forref.d(3): Error: struct forrref.foo unknown size
forref.d(3): Error: struct forrref.foo no size yet for forward reference
===================
Comment 3 Ali Cehreli 2013-08-31 20:05:39 UTC
Manu meant this: :)

  http://d.puremagic.com/issues/show_bug.cgi?id=10766
Comment 4 Manu 2013-08-31 23:00:46 UTC
(In reply to comment #3)
> Manu meant this: :)
> 
>   http://d.puremagic.com/issues/show_bug.cgi?id=10766

Haha, thx ;)
Comment 5 Iain Buclaw 2013-09-18 04:18:33 UTC
This happens because, eg: array literals are initialised by the GC by calling _d_arrayliteralTX (typeinfo, dim);

This requires that the struct has a complete runtime type information about a type.  Something that does not get generated for opaque types, which makes this bug not the easiest to fix - and the same is with other array operations which also require typeinfo to be available.
Comment 6 Manu 2013-09-18 04:39:28 UTC
But the compiler doesn't need to know anything about the type to allocate an array of pointers. Surely the compiler can use/share the typeinfo of void* in this case?
Comment 7 Iain Buclaw 2013-09-18 05:41:37 UTC
(In reply to comment #6)
> But the compiler doesn't need to know anything about the type to allocate an
> array of pointers. Surely the compiler can use/share the typeinfo of void* in
> this case?

Sure we could use void* if is your expectation for typeid(foo*).toString to return "void*"  =)
Comment 8 Manu 2013-09-18 05:46:42 UTC
Surely it can't be hard to synthesize a named pointer type... unless it's dereferenced, it shouldn't need an actual definition in the typeinfo. So it would just be a stub or dummy typeinfo that's empty?
Comment 9 grogan.colin 2013-09-18 05:48:42 UTC
A possible workaround to this is to create the struct like:

struct foo {}

Though, in this case it isn't an opaque struct and is merely a struct with no members.
Comment 10 Kenji Hara 2013-09-28 23:02:28 UTC
*** Issue 10766 has been marked as a duplicate of this issue. ***
Comment 12 github-bugzilla 2013-09-29 12:23:40 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/e7d3e97cdaf4653a39f7f9c68a4868ede2c4bb6b
fix Issue 10451 - Array of pointers to opaque struct gives forward reference errors.

https://github.com/D-Programming-Language/dmd/commit/f2cc07963d2ade375c056b48580d7c638d11f60c
Merge pull request #2594 from 9rnsr/fix10451

Issue 10451 - Array of pointers to opaque struct gives forward reference errors.
Comment 13 Kenji Hara 2013-10-01 19:24:03 UTC
*** Issue 9795 has been marked as a duplicate of this issue. ***