// The compiler tries to parse this as a struct initializer.
auto foo = { while (doSomething()){} }; // Error: expression expected, not 'while'
There are several workarounds to this.
auto foo = { while (doSomething()){;} }; // Insert a semicolon somewhere.
auto foo = (){ while (doSomething()){} }; // Add a ParameterList.
auto foo = delegate void (){ while (doSomething()){} }; // A full delegate expression.
Follwing still fails in trunk dmd 2.054 (d36b3b12fc4814e59f3a0d680b8700e787b1ceff).
auto foo = { while (doSomething()){} };
Workarounds are as same.
Comment #3 by hsteoh — 2014-08-07T23:16:27Z
Still fails in git HEAD (2.067a). :-(
Comment #4 by iamthewilsonator — 2018-11-23T23:24:14Z
2.076.1 to 2.079.1: Failure with output:
-----
onlineapp.d(4): Error: expression expected, not `while`
onlineapp.d(4): Error: comma expected separating field initializers
onlineapp.d(7): Deprecation: use `{ }` for an empty statement, not `;`
-----
Since 2.080.1: Success with output: onlineapp.d(7): Deprecation: use `{ }` for an empty statement, not `;`