You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SUGGESTION] if (i==j) gives clang warning about (i==j) #457
if (i==j) in cpp2, when lowered to cpp1, encloses condition in parens if ((i==j))
Which is, probably, for good, but in modern C++, for example clang, gives a warning
warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
note: remove extraneous parentheses around the comparison to silence this warning
note: use '=' to turn this equality comparison into an assignment
It can be a problem if "threat warnings as error" enabled, in case of mixed cpp1/cpp2.
You're right.
It's only if a = b that's rejected. if (a = b) isn't.
Because the grammar is 'if' logical-or-expression.
So only if (a == b) don't need the redundant parentheses lowered to Cpp1 to avoid warnings.
Or maybe it's good that they're lowered to Cpp1 as-is,
because it means, "hey, you used redundant parentheses in Cpp2!"
Activity
JohelEGP commentedon May 14, 2023
realgdman commentedon May 14, 2023
Hm, looks this cpp2 valid currently
https://cpp2.godbolt.org/z/bGPqKK3nc
prints 0,1,1,0,1,1
JohelEGP commentedon May 14, 2023
You're right.
It's only
if a = bthat's rejected.if (a = b)isn't.Because the grammar is
'if' logical-or-expression.So only
if (a == b)don't need the redundant parentheses lowered to Cpp1 to avoid warnings.Or maybe it's good that they're lowered to Cpp1 as-is,
because it means, "hey, you used redundant parentheses in Cpp2!"
JohelEGP commentedon May 14, 2023
So this is a non-bug (much less a suggestion).
realgdman commentedon May 14, 2023
I should be clearer, cppfront add extra parens. So
if ((i==1))becamesif (((i==1)))etcJohelEGP commentedon May 14, 2023
It's not extra. It's the same you write.
if ais Cpp2, and has to lower to Cpp1if (a).