On Monday, 30 June 2025 at 14:30:49 UTC, Manfred Nowak wrote:
On Sunday, 29 June 2025 at 13:06:38 UTC, Rajesh wrote:
[...]
```d
struct Problem {
this(int val) {
foreach (int number; myType)
return;
```
[...]
Is there a restriction [...]
Yes.
'this' is not allowed to have a 'return' (15.13.0.2) ...
and to exit a 'foreach'-loop needs a 'break' (12.11.0.6).
So the compiler should not compile that program even for
runtime.
Sorry, I didn't see the reference to 15.13.0.2.
But when I read section 15.13.2 of dlang documentation, which
says, "Constructors are defined with a function name of this and
have no return value" my interpretation was that this prohibits
returning an explicit value (like return 5;).
However, I thought a plain return; statement for control flow
(like an early exit) was still allowed.
Could you please let me know if I've misunderstood this point? I
appreciate your help in clarifying.