Closed Bug 43398 Opened 25 years ago Closed 24 years ago

illegal syntax in mozilla header file

Categories

(Core :: XPCOM, defect, P3)

x86
Linux
defect

Tracking

()

RESOLVED INVALID

People

(Reporter: demian.godon, Assigned: kandrot)

Details

File: ~/mozilla/dist/include/nsAReadableString.h Line: 1132 This line contains: if ( int result = nsCharTraits<CharT>::compare(lefIter.get(), rightIter.get(), lengthAvailable) )... This code is generated during a build. A declaration and assignment should not be allowable syntax (I'm not sure why the compiler doesn't complain). I discovered this using a 3rd party tool.
This appears to be valid code to me, although -Wall would warn about it.
I tried a simple representative program with a few different compilers; some compiled, some complained - as such it might be worth correcting but obviously not a showstopper (or even high priority). Here's the sample program (the suspect code being the assignment in the condition): main() { if (int result = 1+1) printf("Hello World\n"); exit(0); } Here's the results: cc - complained when program saved as .c file (parse error before 'int'), compiled as .cpp g++, gcc - compiled cl (MS Visual C++ 6.0) - complained (error C2146: syntax error : missing ')' before identifier 'result' C:/TEMP/syntaxtest2/syntaxtest2.cpp(8) : error C2065: 'result' : undeclared identifier C:/TEMP/syntaxtest2/syntaxtest2.cpp(8) : error C2059: syntax error : ')' Error executing cl.exe.) C-Cover (www.bullseye.com) (this is a code coverage tool) - complained
There is nothing wrong semantically with having an assignment inside a condition. It simply passes on the value of the assignment to the condition, or in other words, the above code is identical to this: main() { int result=1+1; if (result) printf(...); return 0; } where the condition evaluates as true for any result!=0.
C and variants have always had declarations and assignments in the same statement, and in c++ u can have the declarations anywhere.. I'm not very clueful about c++ tho, are u talking about the fact it's inside an if condition?
setting bug status to New
Status: UNCONFIRMED → NEW
Ever confirmed: true
Yes the "problem" is the assignment statement inside the condition. It is a problem because some compilers don't like it. One might also argue that it makes the code more obfuscated.
Summary: illegal syntax in generated mozilla header file → illegal syntax in mozilla header file
Assignee: rayw → warren
Transferring to default XPCOM owner.
QA Contact: leger → kandrot
I can´t see this line with win2k. reassigning to component owner
Assignee: warren → kandrot
QA Contact: kandrot → scc
The code no longer exists, as of 04.02.2001. Was changed with scc's string landing.
Status: NEW → RESOLVED
Closed: 24 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.