Opened 5 years ago
Last modified 4 years ago
#166 assigned defect
Cannot get reference to generic member of generic struct — at Version 2
Reported by: | mlbrooks | Owned by: | mlbrooks |
---|---|---|---|
Priority: | major | Component: | cfa-cc |
Version: | 1.0 | Keywords: | |
Cc: |
Description (last modified by )
Minimal example:
forall( dtype T ) struct a {}; struct b1 { a(int) aa; }; forall( dtype T ) struct b2 { a(T) aa; }; int main() { #ifndef THE_ERROR b1 thingb; #else b2(int) thingb; #endif a(int) & thinga = thingb.aa; }
On the error, message is:
CFA Version 1.0.0 (debug) thebug.cfa: In function ‘_X4mainFi___1’: thebug.cfa:21:36: error: lvalue required as unary ‘&’ operand a(int) & thinga = thingb.aa;
Using a pointer, in place of a reference, is often a workaround. This version compiles properly:
... int main() { b2(int) thingb; a(int) * thinga = &thingb.aa; }
However, the issue prevents defining a constructor for such a generic-of-generic struct. This declaration suffers from the same error.
forall( dtype T ) void ?{}( b2(T) & ) {}
A workaround for the constructor problem (which may often be hard to apply) is to make the b2 parameters sized. This version compiles.
forall( dtype T | sized(T) ) struct b2 { a(T) aa; }; forall( dtype T | sized(T) ) void ?{}( b2(T) & ) {}
Change History (2)
comment:1 Changed 4 years ago by
Description: | modified (diff) |
---|---|
Priority: | major → minor |
Summary: | Cannot access inner member by reference when structs are generic → Cannot get reference to generic member of generic struct |
comment:2 Changed 4 years ago by
Description: | modified (diff) |
---|---|
Priority: | minor → major |
Note: See
TracTickets for help on using
tickets.