Closed Bug 1649112 Opened 5 years ago Closed 5 years ago

nsXPConnect.cpp: using the result of an assignment as a condition without parentheses

Categories

(Core :: XPConnect, task)

task

Tracking

()

RESOLVED WONTFIX

People

(Reporter: Sylvestre, Assigned: Sylvestre)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 1 obsolete file)

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?

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.

Very strange. I thought this syntax was recommended, because unlike if (priv = xpc::CompartmentPrivate::Get(obj)) you can't directly confuse that with ==.

(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&regexp=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&regexp=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&regexp=true

Flags: needinfo?(sledru)

It also doesn't compile with the parentheses I think?

I guess it is an glitch from the CI. It is the only occurrence found by the tool.

Status: NEW → RESOLVED
Closed: 5 years ago
Flags: needinfo?(sledru)
Resolution: --- → WONTFIX
Attachment #9160023 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: