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

Bug 315518

Summary: Invalid Codan error for return statement
Product: [Tools] CDT Reporter: Sergey Prigogin <eclipse.sprigogin>
Component: cdt-codanAssignee: 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:

Description Sergey Prigogin CLA 2010-06-02 19:17:06 EDT
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.
Comment 1 Elena Laskavaia CLA 2010-06-02 20:16:42 EDT
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.
Comment 2 Sergey Prigogin CLA 2010-06-02 20:40:00 EDT
(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.
Comment 3 Elena Laskavaia CLA 2010-06-02 22:47:55 EDT
as workaround you can exclude "test" files from the checker scope
Comment 4 Sergey Prigogin CLA 2010-06-02 23:07:10 EDT
(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
Comment 5 Elena Laskavaia CLA 2010-06-03 09:40:44 EDT
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.
Comment 6 CDT Genie CLA 2010-06-03 23:23:02 EDT
*** 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
Comment 7 Elena Laskavaia CLA 2010-06-08 11:07:16 EDT
was fixed in 7.0. Missing scope tab was fixed too.