995 – compile-time function return element of Tuple / const array

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 995 - compile-time function return element of Tuple / const array
Summary: compile-time function return element of Tuple / const array
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P2 normal
Assignee: Walter Bright
URL:
Keywords:
Depends on:
Blocks:
Reported: 2007年02月22日 06:40 UTC by Daniel
Modified: 2014年02月16日 15:26 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Daniel 2007年02月22日 06:40:12 UTC
compile-time function return element of Tuple
--------------------------------------------------------------------
import std.stdio;
template Tuple(A...) { alias A Tuple; }
template eval(A...) { alias A eval; }
alias Tuple!("a","b") foo;
char[] retsth(int i) { return foo[i]; }
//Error: Integer constant expression expected instead of cast(uint)i
void main()
{
	writefln(eval!(foo[0]));
	//this is working
	writefln(eval!(retsth(0)));
}
--------------------------------------------------------------------
compile-time function return element of const array
--------------------------------------------------------------------
import std.stdio;
template eval(A...) { alias A eval; }
const char[] foo[2] = ["a","b"];
char[] retsth(int i) { return foo[i]; }
void main()
{
	writefln(eval!(foo[0]));
	//this is working (see #975)
	writefln(eval!(retsth(0)));
	//but this makes dmd crash
}
--------------------------------------------------------------------
Comment 1 Daniel 2007年02月22日 11:39:51 UTC
Is this related to the bug ?
--------------------------------------------------------------------
import std.stdio;
template eval(A...) { alias A eval; }
char[] retsth(int i) {
	const char[] foo[2] = ["a","b"];
	return foo[i];
}
//Error: cannot evaluate retsth(0) at compile time
//Error: expression eval!(retsth(0)) is void and has no value
void main()
{
	writefln(eval!(retsth(0)));
}
--------------------------------------------------------------------
PS: Ultimately I would like to be able to do:
writefln(eval!(std.string.stripl(" test"));
Maybe some more string operations could be compile-time ready ?
I am not sure whether this will work if this bug get's fixed,
so maybe this is a feature req ;)
Comment 3 Walter Bright 2007年03月09日 03:48:29 UTC
The first example is not a bug; tuples must be evaluatable at compile time, and i of retsth(i) is not known at compile time when object code is generated for it. The other two are bugs.
Comment 4 Walter Bright 2007年03月19日 17:37:41 UTC
Fixed DMD 1.009


AltStyle によって変換されたページ (->オリジナル) /