Bug 6164 – [CTFE] Local arrays in a recursive local function behave funny
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-06-16T12:40:00Z
Last change time
2011-06-23T00:35:50Z
Assigned to
nobody
Creator
timon.gehr
Comments
Comment #0 by timon.gehr — 2011-06-16T12:40:49Z
This is tt.d:
import std.stdio;
string ctfe(){
int[] ctfe2(int n){
int[] r=[];
if(n!=0) r~=[1]~ctfe2(n-1);
return r;
}
return ctfe2(2).length == 2 ?
"hello from runtime!" : "hello from compile time!";
}
void main(){
pragma(msg,ctfe());
writeln(ctfe());
}
$ dmd -run tt;
hello from compile time!
hello from runtime!
$
The ctfe'd result is generally longer than the correct one.
The example works as expected if ctfe2 is moved outside ctfe.
Comment #1 by kennytm — 2011-06-16T13:07:12Z
A workaround is to make ctfe2 a 'static function'.