Is old style compile-time foreach redundant?

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Jan 9 23:27:42 UTC 2018


On Wed, Jan 10, 2018 at 12:18:46AM +0100, Timon Gehr via Digitalmars-d-learn wrote:
> On 09.01.2018 22:04, H. S. Teoh wrote:
> > 	if (0 == 3) {}
> > 	// all subsequent iterations deleted
> > 
> > because the static break is unconditionally compiled (it has nothing
> > to do with the runtime branch).  You'd have to use static if to make
> > it conditionally-compiled and thus not instantly aborting the loop.
> > 
> > Such semantics would be logically consistent, but unfortunately
> > rather counterintuitive at first glance.
> 
> I think "if (0 == 3) { static break; }" should be a compile-time error.

That's also a possible solution, perhaps a better solution than what I
described.  Make it so that static break/continue cannot be nested
inside runtime conditionals.  That should exclude all of the
pathological cases, hopefully.


T

-- 
The diminished 7th chord is the most flexible and fear-instilling chord. Use it often, use it unsparingly, to subdue your listeners into submission!


More information about the Digitalmars-d-learn mailing list