digitalmars.D.bugs - [Issue 11410] New: Support equality operator chaining
- d-bugmail puremagic.com (53/53) Nov 01 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11410
http://d.puremagic.com/issues/show_bug.cgi?id=11410 Summary: Support equality operator chaining Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: bearophile_hugs eml.cc This is valid C code: int main() { int x = 3; int y = 4; int z = 5; int b = x < y < z; return 0; } Bug GCC tells us that code doesn't work as expected by a Python programmer: test.c:5:15: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses] int b = x < y < z; So D disallows that code: test.d(5): Error: semicolon expected, not '<' test.d(5): Error: found '<' instead of statement - - - - - - - - - - - - - - GCC accepts this code: int main() { int x = 4; int y = 4; int z = 4; int b = x == y == z; return 0; } With a warning: test.c:5:15: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses] int b = x == y == z; While DMD refuses that code: test.d(5): Error: semicolon expected, not '==' test.d(5): Error: found '==' instead of statement From my experience with D code I know there several situations where the chained equality is handy: if (n == foo(n) == bar(n) && ... It avoids code like: aux = foo(n); if (n == aux && aux == bar(n) && ... -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 01 2013