Bug 11795 – DMD allows nested new operator syntax together with anonymous classes
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-12-21T16:18:17Z
Last change time
2020-03-21T03:56:32Z
Assigned to
No Owner
Creator
Bruno Medeiros
Comments
Comment #0 by bruno.do.medeiros+deebugz — 2013-12-21T16:18:17Z
It seems DMD syntactically allows the new operator nested class instantiation syntax together with the anonymous class syntax, like this:
auto outer = new Outer();
outer.new class Inner { };
This syntax never makes sense, because an anonymous class instantiation always defines an outer context by itself (by means of the surrounding scope), so it cannot have another outer scope (ie, the outer class). Using this syntax will always result in a semantic error, or some compiler internal error. For example the following code compiles without semantic errors, but the linker fails:
class Outer {
int foo;
auto x = new Outer().new class Inner {};
class Inner {
}
}
void main() {
}
Comment #1 by b2.temp — 2019-02-13T01:37:32Z
It's a front end error nowadays.
Error: class `temp_7FCDE39084D0.Outer` no size because of forward reference
Although the error message might be better.