nsXPConnect.cpp: using the result of an assignment as a condition without parentheses
Categories
(Core :: XPConnect, task)
Tracking
()
People
(Reporter: Sylvestre, Assigned: Sylvestre)
References
(Blocks 1 open bug)
Details
Attachments
(1 file, 1 obsolete file)
|
89.25 KB,
image/png
|
Details |
| Assignee | ||
Comment 1•5 years ago
|
||
Comment 2•5 years ago
|
||
This seems wrong to me. This specific syntax should not require braces, because it includes a type. Is this a new kind of warning introduced by clang?
| Assignee | ||
Comment 3•5 years ago
|
||
No, it has been around for a while: https://clang.llvm.org/docs/DiagnosticsReference.html#widiomatic-parentheses
It is just best practice as it clearly highlight to humans that it is really what we want to do and not a typo.
| Assignee | ||
Comment 4•5 years ago
|
||
Comment 5•5 years ago
|
||
Very strange. I thought this syntax was recommended, because unlike if (priv = xpc::CompartmentPrivate::Get(obj)) you can't directly confuse that with ==.
Comment 6•5 years ago
•
|
||
(In reply to Sylvestre Ledru [:Sylvestre] from comment #3)
No, it has been around for a while: https://clang.llvm.org/docs/DiagnosticsReference.html#widiomatic-parentheses
It is just best practice as it clearly highlight to humans that it is really what we want to do and not a typo.
I agree in the general case, but I agree with Tom that this is a special pattern that we use in hundreds of places without parentheses. Here are some results:
https://searchfox.org/mozilla-central/search?q=if+%5C%28dom%3A%3A.*%5B%5E%21%5D%3D%5B%5E%3D%5D&path=&case=false®exp=true
https://searchfox.org/mozilla-central/search?q=if+%5C%28mozilla%3A%3A.*%5B%5E%21%5D%3D%5B%5E%3D%5D&path=&case=false®exp=true
https://searchfox.org/mozilla-central/search?q=if+%5C%28js%3A%3A.*%5B%5E%21%5D%3D%5B%5E%3D%5D&path=&case=false®exp=true
Comment 7•5 years ago
|
||
It also doesn't compile with the parentheses I think?
| Assignee | ||
Comment 8•5 years ago
|
||
I guess it is an glitch from the CI. It is the only occurrence found by the tool.
Updated•5 years ago
|
Description
•