Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 313622 - "Suggested parenthesis around expression" make check for (!b && a) cases optional
Summary: "Suggested parenthesis around expression" make check for (!b && a) cases opti...
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-codan (show other bugs)
Version: 7.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Elena Laskavaia CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-19 16:15 EDT by Vadym Krevs CLA
Modified: 2010-07-28 15:29 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vadym Krevs CLA 2010-05-19 16:15:32 EDT
Build Identifier:  I20100518-0800

Create a new CPP file containing just the following function:

int this_is_a_test()
{
    bool a(false), b(true);
    return (!b && a)
}

Problem analysis highlights "!b" and adds  a "Suggested parenthesis around expression" warning to the problems list.

Reproducible: Always
Comment 1 Elena Laskavaia CLA 2010-05-19 21:21:12 EDT
Correct. This is warning generated by code analysis tool. You can
either "surround by parenthesis" ((!b) && a)
or turn off this error in Project or Workspace preferences
under C/C++ -> Code Analysis
Comment 2 Andrew Gvozdev CLA 2010-05-19 21:29:18 EDT
Note that there is potential ambiguity which is reported by the tool. The expression could be incorrectly interpreted by somebody as 
   return ( ! (b && a) )
Comment 3 Vadym Krevs CLA 2010-05-20 01:40:55 EDT
There is no ambiguity according to C/C++ language definition. And no one with a modicum of C/C++ knowledge will interpret (!b && a) as !(b && a). 

IMHO, at the very least, this warning should not be on by default. Ideally, it should only report much more complex boolean expressions.
Comment 4 Elena Laskavaia CLA 2010-05-20 10:43:49 EDT
There is no ambiguity according to C even if you write (1 < x < 3)
but it does not help people who don't know c precedence of operators.

I agree that this specific one (about !b) is less likely to be confusing.
Currently checker finds some other cases too. I will try to add a parameter to
suppress this case, which would be on by default.

I re-open this to implement it.
Comment 5 Vadym Krevs CLA 2010-05-20 15:57:39 EDT
Alena, thank you. 

Perhaps, a better way of dealing with this issue, is to have a "Beginner/Expert" mode for Code Analysis settings - with all warnings enabled for the beginner mode, and only a smaller selection - for the expert mode.

Just a suggestion.
Comment 6 Elena Laskavaia CLA 2010-05-20 16:33:54 EDT
Please submit another bug for that. It is called "Problem Profiles", I did not
get a chance to work on that yet.
Comment 8 Elena Laskavaia CLA 2010-05-30 19:57:12 EDT
fixed
Comment 9 CDT Genie CLA 2010-07-28 15:29:33 EDT
*** cdt cvs genie on behalf of elaskavaia ***
Bug 313622 Make checking for !a && b optional and off by default

[*] SuggestedParenthesisChecker.java 1.6 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/SuggestedParenthesisChecker.java?root=Tools_Project&r1=1.5&r2=1.6