Bug 5143 – Static array of function literals

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-10-31T06:15:00Z
Last change time
2010-10-31T13:47:12Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs
See also
http://d.puremagic.com/issues/show_bug.cgi?id=2634

Comments

Comment #0 by bearophile_hugs — 2010-10-31T06:15:06Z
This code works correctly with DMD 2.050: void f1(int a) {} static void function(int a)[] foo = [&f1]; void main() {} But this doesn't compile: static void function(int a)[] foo = [function(int a) {}]; void main() {} The error message: test.d(1): Error: non-constant expression __funcliteral1 I think this second version of the code too is correct.
Comment #1 by adrian — 2010-10-31T07:33:54Z
upvoted!
Comment #2 by denis.spir — 2010-10-31T13:07:38Z
The bug report states an issue about func arrays, but: // ok void f () {} ; static void function() foo = &f ; // not ok static void function() foo = function void() {}; --> Error: non-constant expression __funcliteral1 It seems to me the issue is that one cannot initialise a function variable with the expression of a function. (Array or not.) What does the compiler expect there? What does the error mean? As we have function literals, they should, I guess, be usable where other literals are accepted. Note: auto foo = function void() {}; throws the same error. Denis
Comment #3 by denis.spir — 2010-10-31T13:18:01Z
(In reply to comment #2) This is already filed as bug 2634 "Function literals are non-constant". http://d.puremagic.com/issues/show_bug.cgi?id=2634. Denis
Comment #4 by bearophile_hugs — 2010-10-31T13:47:12Z
*** This issue has been marked as a duplicate of issue 2634 ***