5147 – [CTFE] Return fixed-sized matrix

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5147 - [CTFE] Return fixed-sized matrix
Summary: [CTFE] Return fixed-sized matrix
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
Reported: 2010年10月31日 14:20 UTC by bearophile_hugs
Modified: 2011年04月08日 21:20 UTC (History)
2 users (show)

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 bearophile_hugs 2010年10月31日 14:20:21 UTC
This is borderline between enhancement and rejects-valid bug report.
DMD 2.050 doesn't support this code:
int[1][1] foo() {
 int[1][1] a;
 return a;
}
enum int[1][1] m1 = foo();
immutable int[1][1] m2 = foo();
void main() {}
Errors generated:
test.d(2): Error: Slice operation a[] = 0 cannot be evaluated at compile time
test.d(5): Error: cannot evaluate foo() at compile time
This code is very useful to initialize an enum/immutable global matrix.
Comment 1 Michal Minich 2010年10月31日 14:49:37 UTC
I would like to point out that this code works:
int[1] foo2() {
 int[1] a;
 return a;
}
enum int[1] m3 = foo2();
immutable int[1] m4 = foo2();
void main() {}
Comment 2 bearophile_hugs 2010年10月31日 16:31:43 UTC
See also bug 5081 for a different solution
Comment 3 Don 2011年04月08日 21:20:10 UTC
This is definitely a bug, not an enhancement. It applies to any use of multidimensional static arrays in CTFE (not just return values). Thus, it also applies to D1.
Fixed.
D1:
https://github.com/D-Programming-Language/dmd/commit/ef2a0f1da10331c4de102ca3e029ea1c1c1a46bf
D2:
https://github.com/D-Programming-Language/dmd/commit/0219a5f0dcc88076759a4c472582954d0fb804b0 


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