| Summary: | Invalid Codan error for return statement | ||
|---|---|---|---|
| Product: | [Tools] CDT | Reporter: | Sergey Prigogin <eclipse.sprigogin> |
| Component: | cdt-codan | Assignee: | Elena Laskavaia <elaskavaia.cdt> |
| Status: | RESOLVED FIXED | QA Contact: | Elena Laskavaia <elaskavaia.cdt> |
| Severity: | major | ||
| Priority: | P3 | CC: | cdtdoug |
| Version: | 7.0 | ||
| Target Milestone: | 7.0 | ||
| Hardware: | PC | ||
| OS: | Linux | ||
| Whiteboard: | |||
Everything that codan finds so far is in the "valid" code.
This is valid too in C
int foo(){
return;
}
parser would complain but not much.
I deliberate left this case in, because I don't see a reason to write
a code like that. I can add checker parameter at most.
(In reply to comment #1) > I deliberate left this case in, because I don't see a reason to write > a code like that. Googletest framework (http://http://code.google.com/p/googletest) uses this construct in assertion macros. as workaround you can exclude "test" files from the checker scope (In reply to comment #3) > as workaround you can exclude "test" files from the checker scope How do I do that? The scope tab just says: No extra preferences Hmm. Let me check. It should have scope tab. What version you are using? Btw after sleeping on it I think this case should be remove from this checker because "Return has value, in function returning void" is wrong in this case. If I want to produce a problem in this case it should be "Return with void type" or something like this. *** cdt cvs genie on behalf of elaskavaia *** Bug 315518 - fixed case where checker would report return with value while expression is void [*] ReturnChecker.java 1.12 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java?root=Tools_Project&r1=1.11&r2=1.12 was fixed in 7.0. Missing scope tab was fixed too. |
C++ standard considers the following code valid, but Codan complains "Return has value, in function returning void". void f(); void g() { return f(); } Here is an excerpt from the standard: 3.9.1-9 The void type has an empty set of values. The void type is an incomplete type that cannot be completed. It is used as the return type for functions that do not return a value. Any expression can be explicitly converted to type cv void (5.4). An expression of type void shall be used only as an expression statement (6.2), as an operand of a comma expression (5.18), as a second or third operand of ?: (5.16), as the operand of typeid, or as the expression in a return statement (6.6.3) for a function with the return type void.