www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - problems with aliasing nested templates

1) This compiles just fine:


template Outer( T, size_t sizeofT : int.sizeof = T.sizeof )
{
template fn( int i : 0 )
{
T fn( inout T val )
{
return val;
}
}

template fn( int i : 1 )
{
alias fn0 fn;
}

private alias fn!(0) fn0;
}

void main()
{
int i;
Outer!(int).fn!(1)( i );
}


2) As does this:


template Outer( T, size_t sizeofT : int.sizeof = T.sizeof )
{
template fn( int i : 0 )
{
T fn( inout T val )
{
return val;
}
}

template fn( int i : 1 )
{
alias .Outer!(T,sizeofT).fn!(0) fn;
}
}

void main()
{
int i;
Outer!(int).fn!(1)( i );
}


3) This does not:


template Outer( T, size_t sizeofT : int.sizeof = T.sizeof )
{
template fn( int i : 0 )
{
T fn( inout T val )
{
return val;
}
}

private alias fn!(0) fn0;

template fn( int i : 1 )
{
alias fn0 fn;
}
}


void main()
{
int i;
Outer!(int).fn!(1)( i );
}

test.d(11): template instance forward reference to template
test.d(23): template instance test.Outer!(int) error instantiating
test.d(23): function expected before (), not template instance fn!(1) of type vo
id


4) Neither does this:


template Outer( T, size_t sizeofT : int.sizeof = T.sizeof )
{
template fn( int i : 0 )
{
T fn( inout T val )
{
return val;
}
}

template fn( int i : 1 )
{
alias fn!(0) fn;
}
}


void main()
{
int i;
Outer!(int).fn!(1)( i );
}

test.d(13): alias test.Outer!(int).fn!(1).fn recursive alias declaration
test.d(13): template instance fn is not a template declaration, it is a alias
test.d(21): template instance test.Outer!(int).fn!(1) error instantiating
test.d(21): function expected before (), not template instance fn!(0) of type vo
id


I can live with the second form.  That the third doesn't work looks like a bug.
And I can understand why the fourth might be invalid, but it still seems a bit
odd to me.  It would be nice if there were a way to declare template functions
without having to create the nested scope.


Sean
Jul 26 2005