bug with auto or what?

Minas Mina minas_mina1990 at hotmail.co.uk
Mon Aug 13 12:09:03 PDT 2012


I'm writing an insert() function for a binary tree in D:

Note: Node is a value type (struct)

Node!(T)* insert(T) (Node!(T)* root, T val)
{
	if( root is null )
	{
		root = new Node!T();
		root.value = val;
		root.left = root.right = null;
	}
	else
	{
		if( val < root.value )
			root.left = insert(root.left, val);
		else
			root.right = insert(root.right, val);
	}
	
	return root;
}


This works (compiles).


auto insert(T) (Node!(T)* root, T val)
{
	if( root is null )
	{
		root = new Node!T();
		root.value = val;
		root.left = root.right = null;
	}
	else
	{
		if( val < root.value )
			root.left = insert(root.left, val); // line x
		else
			root.right = insert(root.right, val); // line y
	}
	
	return root;
}

This doesn't compile.

test.d(x): Error: forward reference to inferred return type of 
function call insert((*root).left,val)
test.d(y): Error: forward reference to inferred return type of 
function call insert((*root).right,val)

Is it a bug with auto or something else?


More information about the Digitalmars-d mailing list