﻿id	summary	reporter	owner	description	type	status	priority	component	version	resolution	keywords	cc
166	Cannot get reference to generic member of generic struct	mlbrooks	mlbrooks	"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) & ) {}
}}}
"	defect	assigned	major	cfa-cc	1.0			
