[Issue 6176] [tdpl] Cannot use string variables in case expressions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 18 13:50:30 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=6176



--- Comment #22 from Jonathan M Davis <jmdavisProg at gmx.com> 2012-01-18 13:50:26 PST ---
> `if (x = foo())` can't work, so I don't know why `switch (x = foo())` can.

That's easy. With if, there's a strong possibility that the programmer really
meant to use ==. So, by disallowing = by itself, you avoid those bugs (though
it would certainly be nice to be able to do if(x = foo()) - gcc allows it
without complaining if you add extra parens (though IIRC Visual Studio doesn't
like it) - if((x = foo()) - but I don't think that D has anything of the sort).

However, the switch statement requires a value, not an expression, so the risk
of = being used instead of == is pretty much zero. So, disallowing it for
switch doesn't really benefit anyone.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list