-
Notifications
You must be signed in to change notification settings - Fork 277
Space and bracket pretty-printed ternary conditionals #3474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Space and bracket pretty-printed ternary conditionals #3474
Conversation
At the moment we get e.g. y == x == z?1:2, this changes that to y == (x == z ? 1 : 2) which makes the precedence clearer and spaces the operator more cleanly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
Passed Diffblue compatibility checks (cbmc commit: ca55615).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/92815813
<< ':' << format(if_expr.false_case()); | ||
return os << "(" << format(if_expr.cond()) << " ? " | ||
<< format(if_expr.true_case()) << " : " | ||
<< format(if_expr.false_case()) << ")"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use '(' etc. for the single letters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (plus two other similar changes in the same file)
Shouldn't we properly do precedence instead, much like |
I would add the parentheses for any use of ?: as subexpression. Precendences can be tough for the reader when they go beyond the ones we learn in primary school. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
Passed Diffblue compatibility checks (cbmc commit: d4d7af4).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/92978446
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not going to stand in the way with my (poor) taste when it comes to places parentheses ;-)
At the moment we get e.g. y == x == z?1:2, this changes that to y == (x == z ? 1 : 2)
which makes the precedence clearer and spaces the operator more cleanly.