Bug 2634 – Function literals are non-constant.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2009-01-29T12:35:00Z
Last change time
2014-04-18T09:12:06Z
Keywords
rejects-valid
Assigned to
nobody
Creator
burton-radons

Comments

Comment #0 by burton-radons — 2009-01-29T12:35:46Z
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 by bearophile_hugs — 2010-10-31T13:47:12Z
*** Issue 5143 has been marked as a duplicate of this issue. ***
Comment #2 by dmttding — 2011-03-11T14:35:35Z
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.
Comment #3 by yebblies — 2011-08-31T22:38:27Z
Comment #4 by bugzilla — 2011-08-31T23:24:22Z