https://dlang.org/spec/expression.html says "If a NewExpression is used as an initializer for a function local variable with scope storage class, and the ArgumentList to new is empty, then the instance is allocated on the stack rather than the heap or using the class specific allocator."
Does it mean that in the following program an object of C
is allocated entirely on the stack, without any heap allocation?
class C {
int x;
}
void main() {
scope c = new C();
}
Also: Why does it work only for empty argument list?
I doubt that I understand correctly, because all the rest D materials I read say that classes are allocated on the heap. I want to make sure.
new
itself (which is rarely used), which are separate from arguments to the class constructor. – Adam D. Ruppe