Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 317042

Summary: [fn] codan doesn't detect assignment in condition in while loops and conditional operators
Product: [Tools] CDT Reporter: Meisam <meisam.fathi>
Component: cdt-codanAssignee: Elena Laskavaia <elaskavaia.cdt>
Status: RESOLVED FIXED QA Contact: Elena Laskavaia <elaskavaia.cdt>
Severity: normal    
Priority: P3 CC: cdtdoug
Version: 7.0   
Target Milestone: 8.0   
Hardware: PC   
OS: All   
Whiteboard:
Attachments:
Description Flags
Patch elaskavaia.cdt: iplog+

Description Meisam CLA 2010-06-16 09:12:36 EDT
This remains undetected by codan:

(a = b) ? do_somthing() : do_something_else();

also this one:

while (a  = b){
  foo();
}

and this one:

do {
  bar();
 }while (a = b);
Comment 1 Meisam CLA 2010-06-16 09:55:48 EDT
Created attachment 172039 [details]
Patch

Apparently this patch solves the problem.
Comment 2 Elena Laskavaia CLA 2010-06-16 09:57:52 EDT
thanks for the patch, -> 7.0.1
Comment 3 Elena Laskavaia CLA 2010-06-19 14:10:09 EDT
I don't think you tested your patch. Condition  
prop == IASTConditionalExpression.LOGICAL_CONDITION 
cannot be true for assignment expression because if you write
a=b?a:b; - it will be a=(b?a:b), and if you write (a=b)?a:b;
parent of assignment expression is unary bracket expression not ternary expression.

Anyway I fix it on head and added tests. Thanks.