D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2634 - Function literals are non-constant.
Summary: Function literals are non-constant.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
: 5143 (view as issue list)
Depends on:
Blocks:
 
Reported: 2009-01-29 12:35 UTC by Burton Radons
Modified: 2014-04-18 09:12 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Burton Radons 2009-01-29 12:35:46 UTC
This code fails compilation:

  void test () { }

  // Compiles okay.
  auto a = &test;

  // Error: non-constant expression __funcliteral1
  auto b = function void () { }; 

As far as I can tell there is no reason for function literals to be non-constant if they're not synthesized during runtime.
Comment 1 bearophile_hugs 2010-10-31 13:47:12 UTC
*** Issue 5143 has been marked as a duplicate of this issue. ***
Comment 2 Taylor Everding 2011-03-11 14:35:35 UTC
It may be useful to know that 

void main() {
  auto a = function void() {};
}

compiles correctly, but when a is moved outside main the Error occurs.