D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3755 - Forward declaration templates something (D1 only)
Summary: Forward declaration templates something (D1 only)
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2010-01-30 06:15 UTC by borislav.asdf
Modified: 2019-10-24 12:23 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description borislav.asdf 2010-01-30 06:15:21 UTC
It used to work in 1.055 now it says

bug.d(6): Error: declaration _D3bug1A6__initZ forward declaration
bug.d(34): Error: template instance bug.Tuple!(_D3bug1A6__initZ) error instantiating
bug.d(38):        instantiated from here: InitsOf!(A)
bug.d(54):        instantiated from here: MinArgs!(func)


//////////////////////////
//////////////////////////
//////////////////////////

struct A {
}

//////////////////////////
//////////////////////////
//////////////////////////

template ParameterTupleOf( Fn )
{
    static if( is( Fn Params == function ) )
        alias Params ParameterTupleOf;
    else static if( is( Fn Params == delegate ) )
        alias ParameterTupleOf!(Params) ParameterTupleOf;
    else static if( is( Fn Params == Params* ) )
        alias ParameterTupleOf!(Params) ParameterTupleOf;
    else
        static assert( false, "Argument has no parameters." );
}

template Tuple( TList... )
{
    alias TList Tuple;
}

template InitsOf(T...) {
	static if(T.length == 0)
		alias Tuple!() InitsOf;
	else
		alias Tuple!(T[0].init, InitsOf!(T[1 .. $])) InitsOf;
}

template MinArgs(alias func) {
	const uint MinArgs = MinArgsImpl!(func, 0, InitsOf!(ParameterTupleOf!(typeof(&func))));
}

private template MinArgsImpl(alias func, int index, Args...) {
	static if(index >= Args.length)
		const uint MinArgsImpl = Args.length;
	else static if(is(typeof(func(Args[0 .. index]))))
		const uint MinArgsImpl = index;
	else
		const uint MinArgsImpl = MinArgsImpl!(func, index + 1, Args);
}	

void func(A) {
}

void main() {
	const a = MinArgs!(func);
}
Comment 1 Don 2010-07-26 08:25:02 UTC
This is not a regression. The behaviour in 1.056 is the same as in 1.054. In 1.055, it didn't generate any error messages, but that was because the compiler was crashing!
Interestingly the code works on 2.043 and later.
Comment 2 RazvanN 2019-10-24 12:23:25 UTC
Closing as D1 is no longer supported.