D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6598 - Function literals are rejected by structure initializers as non-constant
Summary: Function literals are rejected by structure initializers as non-constant
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-03 06:30 UTC by Maksim Zholudev
Modified: 2012-04-28 04:16 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Maksim Zholudev 2011-09-03 06:30:41 UTC
***** Description: *****

The following code will not compile with DMD64 D Compiler v2.055 (from github):

----------
auto func = function double(double x) {return x;}; // OK

struct Foo {double function(double) func;}
auto f1 = Foo(function double(double x) {return x;}); // Error

void main()
{
    auto f2 = Foo(function double(double x) {return x;}); // OK
}
----------
Error: non-constant expression cast(double function(double))function pure nothrow @safe double(double x)
----------

Compilation fails only if the initializer is placed outside main function.


***** Suspecting: *****

This can be related to Issue 2634 (fixed).
Comment 1 SomeDude 2012-04-27 14:20:37 UTC
Compiles with 2.059 Win32
Comment 2 Maksim Zholudev 2012-04-28 04:16:19 UTC
Compiles with DMD64 D Compiler v2.059 on 64-bit Linux