1464 – "static" foreach breaks CTFE

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1464 - "static" foreach breaks CTFE
Summary: "static" foreach breaks CTFE
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords: rejects-valid
Depends on:
Blocks:
Reported: 2007年08月31日 10:28 UTC by Reiner Pope
Modified: 2015年06月09日 01:14 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 Reiner Pope 2007年08月31日 10:28:14 UTC
The following code gives compile-time error, "cannot evaluate gen() at compile time." Removing the "i" from the foreach fixes this.
template Tuple(T...)
{
	alias T val;
}
alias Tuple!(int) Tup;
string gen()
{
 foreach (i, type; Tup.val)
 {
 }
 return null;
}
string text = gen();
Comment 1 sa 2007年08月31日 17:05:24 UTC
BCS wrote:
> d-bugmail@puremagic.com wrote:
>> http://d.puremagic.com/issues/show_bug.cgi?id=1464
>>
>> Summary: "static" foreach breaks CTFE
>> Product: D
>> Version: 2.003
>> Platform: PC
>> OS/Version: Windows
>> Status: NEW
>> Keywords: rejects-valid
>> Severity: normal
>> Priority: P2
>> Component: DMD
>> AssignedTo: bugzilla@digitalmars.com
>> ReportedBy: reiner.pope@gmail.com
>>
>>
>> The following code gives compile-time error, "cannot evaluate gen() at 
>> compile
>> time." Removing the "i" from the foreach fixes this.
>>
>> template Tuple(T...)
>> {
>> alias T val;
>> }
>>
>> alias Tuple!(int) Tup;
>>
>> string gen()
>> {
>> foreach (i, type; Tup.val)
>> {
>> }
>> return null;
>> }
>>
>> string text = gen();
>>
>>
> 
> 
> That compiles at all? in the 1.x versions you can't have an alias of a 
> tuple in a template other than if the tuple name is the same as the name 
> of the template (It's a known bug, not a language restriction)
It's aliasing the template instantiation, not the tuple. It should 
compile in 1.x as well as 2.x.
Comment 2 Walter Bright 2007年09月28日 22:16:57 UTC
Fixed dmd 1.021 and 2.004


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