5143 – Static array of function literals

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5143 - Static array of function literals
Summary: Static array of function literals
Status: RESOLVED DUPLICATE of issue 2634
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日 06:15 UTC by bearophile_hugs
Modified: 2010年10月31日 13:47 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日 06:15:06 UTC
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 Adrian Matoga 2010年10月31日 07:33:54 UTC
upvoted!
Comment 2 Denis Derman 2010年10月31日 13:07:38 UTC
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 Denis Derman 2010年10月31日 13:18:01 UTC
(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 bearophile_hugs 2010年10月31日 13:47:12 UTC
*** This issue has been marked as a duplicate of issue 2634 ***


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