| Summary: | "Suggested parenthesis around expression" make check for (!b && a) cases optional | ||
|---|---|---|---|
| Product: | [Tools] CDT | Reporter: | Vadym Krevs <vkrevs> |
| Component: | cdt-codan | Assignee: | Project Inbox <cdt-core-inbox> |
| Status: | RESOLVED FIXED | QA Contact: | Elena Laskavaia <elaskavaia.cdt> |
| Severity: | normal | ||
| Priority: | P3 | CC: | cdtdoug, malaperle, vkrevs |
| Version: | 7.0 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Linux | ||
| Whiteboard: | |||
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 Note that there is potential ambiguity which is reported by the tool. The expression could be incorrectly interpreted by somebody as return ( ! (b && a) ) 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. 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. 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. Please submit another bug for that. It is called "Problem Profiles", I did not get a chance to work on that yet. *** cdt cvs genie on behalf of elaskavaia *** Bug 313622 Make checking for !a && b optional and off by default [*] SuggestedParenthesisChecker.java 1.5 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.4&r2=1.5 [*] CheckerTestCase.java 1.10 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CheckerTestCase.java?root=Tools_Project&r1=1.9&r2=1.10 [*] SuggestedParenthesisCheckerTest.java 1.3 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/SuggestedParenthesisCheckerTest.java?root=Tools_Project&r1=1.2&r2=1.3 fixed *** 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 |
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