Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
February 16, 2015 [Issue 14186] Silent syntax change from C and C++ | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=14186 ag0aep6g@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ag0aep6g@gmail.com --- Comment #1 from ag0aep6g@gmail.com --- I'm not well-versed in C/C++, but according to these pages: http://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html#Operator-Precedence (points 13 and 14) http://en.cppreference.com/w/cpp/language/operator_precedence#content (point 15) it's C++ that deviated from C. Whereas D is line with C. A little test with gcc and g++ seems to confirm that: ---- #include <stdio.h> int main() { int b = 1, c = 1; 1 ? b : c = 0; printf("%d\n", b); return 0; } ---- Compiling with gcc gives ---- test.c: In function ‘main’: test.c:5:15: error: lvalue required as left operand of assignment 1 ? b : c = 0; ^ ---- Compiling with g++ succeeds, and running prints "1". -- |
February 16, 2015 [Issue 14186] Silent syntax change from C and C++ | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=14186 --- Comment #2 from Sobirari Muhomori <dfj1esp02@sneakemail.com> --- Interesting, C99 and C11 don't allow for that: assignment-expression: conditional-expression unary-expression assignment-operator assignment-expression i.e. same precedence right-to-left associative. -- |
February 16, 2015 [Issue 14186] Silent syntax change from C and C++ | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=14186 --- Comment #3 from Sobirari Muhomori <dfj1esp02@sneakemail.com> --- Can you confirm it with --std=c99 -pedantic? -- |
February 16, 2015 [Issue 14186] Silent syntax change from C and C++ | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=14186 --- Comment #4 from ag0aep6g@gmail.com --- (In reply to Sobirari Muhomori from comment #3) > Can you confirm it with --std=c99 -pedantic? Same error: ---- $ gcc --std=c99 -pedantic test.c test.c: In function ‘main’: test.c:5:15: error: lvalue required as left operand of assignment 1 ? b : c = 0; ^ $ gcc --version gcc (Ubuntu 4.9.1-16ubuntu6) 4.9.1 ---- -- |
February 16, 2015 [Issue 14186] Silent syntax change from C and C++ | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=14186 --- Comment #5 from Sobirari Muhomori <dfj1esp02@sneakemail.com> --- Looks like gcc has some history under this issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=6905 -- |
February 16, 2015 [Issue 14186] Silent syntax change from C and C++ | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=14186 --- Comment #6 from ag0aep6g@gmail.com --- (In reply to Sobirari Muhomori from comment #5) > Looks like gcc has some history under this issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=6905 That ticket is about C++ though. But if C99 changed/clarified the operator precedence, gcc seems to be buggy in that regard. For D that raises the question what version of C we're aiming for. K&R C, contemporary ANSI C, C as popular compilers understand it, ...? -- |
March 25, 2015 [Issue 14186] Silent syntax change from C and C++ | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=14186 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |yebblies@gmail.com --- Comment #7 from yebblies <yebblies@gmail.com> --- A better option might be to make it a parse error, like we did with a < b < c. -- |
June 10, 2015 [Issue 14186] Silent syntax change from C and C++ | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=14186 Andrei Alexandrescu <andrei@erdani.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Version|D1 & D2 |D2 -- |
October 15, 2018 [Issue 14186] Silent syntax change from C and C++ | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=14186 Nick Treleaven <nick@geany.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |nick@geany.org Resolution|--- |DUPLICATE --- Comment #8 from Nick Treleaven <nick@geany.org> --- (In reply to ag0aep6g from comment #1) > int b = 1, c = 1; > 1 ? b : c = 0; The quoted code is now deprecated: Deprecation: `1 ? b : c` must be surrounded by parentheses when next to operator `=` *** This issue has been marked as a duplicate of issue 18743 *** -- |
Copyright © 1999-2021 by the D Language Foundation