Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 352267 - Assignment in condition checker matches the whole expression
Summary: Assignment in condition checker matches the whole expression
Status: VERIFIED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-codan (show other bugs)
Version: 8.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 8.2.1   Edit
Assignee: Nathan Ridge CLA
QA Contact: Elena Laskavaia CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-16 07:29 EDT by Gil Barash CLA
Modified: 2013-09-01 14:10 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gil Barash CLA 2011-07-16 07:29:35 EDT
Build Identifier: Eclipse I20110613-1736 CDT 8.0

This is a reopen of bug 307414

For the statement: if( a == 1 && b = 2 )
The whole expression "a == 1 && b = 2" is marked and not only "b = 2",
because of this, the quick fix does the following wrong fix:
if( a === 1 && b = 2 )
See comments 6 & 7 in 307414.


Reproducible: Always
Comment 1 Tomasz Wesolowski CLA 2011-08-01 06:03:52 EDT
Let me remind that this happens because it is parsed as (a == 1 && b) = 2. I agree that this needs to be cleverly handled.

More test similar cases would be useful. Can you think of any similar but different situations where substituting = by == would change the operator order?
Comment 2 Nathan Ridge CLA 2013-07-22 21:40:17 EDT
(In reply to comment #1)
> Let me remind that this happens because it is parsed as (a == 1 && b) = 2. I
> agree that this needs to be cleverly handled.
> 
> More test similar cases would be useful. Can you think of any similar but
> different situations where substituting = by == would change the operator
> order?

This warning is predicated on the assumption that the user intended == rather than =. It follows, then, that the user also intended the precedence that comes with == rather than the precedence that comes with =.
Comment 3 Nathan Ridge CLA 2013-07-23 01:29:23 EDT
Patch: https://git.eclipse.org/r/14764
Comment 4 CDT Genie CLA 2013-07-24 23:22:02 EDT
*** cdt git genie on behalf of Nathan Ridge ***

    Bug 352267 - Assignment in condition checker matches the whole
    expression
    Change-Id: I7aea1c5d404a8d374020e34c997e6e890fcdb3d6
    Signed-off-by: Nathan Ridge <zeratul976@xxxxxxxxxxx>
    Reviewed-on: <a  href="https://git.eclipse.org/r/14764">https://git.eclipse.org/r/14764</a>
    Reviewed-by: Sergey Prigogin &lt;eclipse.sprigogin@xxxxxxxxx&gt;
    IP-Clean: Sergey Prigogin &lt;eclipse.sprigogin@xxxxxxxxx&gt;
    Tested-by: Sergey Prigogin &lt;eclipse.sprigogin@xxxxxxxxx&gt;

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=bb84b5cba3e1948297c22ed4f327a2e74973c6da
Comment 5 Marc-André Laperle CLA 2013-07-29 12:16:48 EDT
Fixed in 8.2.1 and master.
Comment 6 Marc-André Laperle CLA 2013-09-01 14:10:53 EDT
Verified in 8.2.1 RC1 (EPP 20130821-2252).