Thread overview |
---|
October 23, 2008 [Issue 2427] New: Function call in struct initializer fails to compile | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=2427 Summary: Function call in struct initializer fails to compile Product: D Version: 2.020 Platform: PC OS/Version: Windows Status: NEW Keywords: rejects-valid Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: samukha@voliacable.com Compiler tries to CTFE the function: struct S { int x; } int foo(int i) { return i; } void main() { int i; S s = { foo(i) }; return 0; } ---- test.d(20): Error: variable i is used before initialization -- |
October 23, 2008 [Issue 2427] Function call in struct initializer fails to compile | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2427 ------- Comment #1 from samukha@voliacable.com 2008-10-23 09:45 ------- 'return 0;' in the example is noise. please ignore it. -- |
October 26, 2008 [Issue 2427] Function call in struct initializer fails to compile | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2427 bugzilla@digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID ------- Comment #2 from bugzilla@digitalmars.com 2008-10-26 04:41 ------- The { } initializers for structs are for statically initialized data only. To use a dynamic initializer, S s = S( foo(i) ); -- |
October 26, 2008 [Issue 2427] Function call in struct initializer fails to compile | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2427 samukha@voliacable.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|INVALID | ------- Comment #3 from samukha@voliacable.com 2008-10-26 05:14 ------- From the spec: "The static initializer syntax can also be used to initialize non-static variables, provided that the member names are not given. The initializer need not be evaluatable at compile time. void test(int i) { S s = { 1, i }; // q.a = 1, q.b = i, q.c = 0, q.d = 7 }" -- |
Copyright © 1999-2021 by the D Language Foundation