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

Bug 311268

Summary: [code analysis] does not detect if a return statement has a expression or not
Product: [Tools] CDT Reporter: Felipe <felipe.m.figueroa>
Component: cdt-codanAssignee: Project Inbox <cdt-core-inbox>
Status: RESOLVED FIXED QA Contact: Elena Laskavaia <elaskavaia.cdt>
Severity: normal    
Priority: P3 CC: cdtdoug
Version: 7.0   
Target Milestone: 7.0   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposal to check the returns expressions and report warning accordingly elaskavaia.cdt: iplog+

Description Felipe CLA 2010-04-30 22:11:35 EDT
Build Identifier: I20100312-1448

In a function as follows CODAN does not report there is no expression for the return statement.

int integer_return_function(void) {
	if (global) {
		if (global == 100) {
			return; // error here on line 4
		}
	}
}


Reproducible: Always

Steps to Reproduce:
1.Write a non void C function
2.Within the function write a return statement without expression.
3.See the Eclipse CDT problems window.  Nothing is reported regarding the missing expression.
Comment 1 Felipe CLA 2010-04-30 22:42:08 EDT
Created attachment 166710 [details]
Proposal to check the returns expressions and report warning accordingly
Comment 2 Elena Laskavaia CLA 2010-05-07 22:58:50 EDT
I created a checker (sorry did not realize there is a patch, it is different code)
I applied tests from patch though.

It checks for
1) Return without a value for function EXPLICITLY defined with non-void return
2) Return with a value for function defined with void
3) No return at all for function EXPLICITLY defined with non-void return



There are few issues now
a) For #1 it may need a parameter to also return errors on function with implicit int (in this case exclude constructors)
b) in case of #3 it has false positive if function does exit() or throw 
c) It has f.p. in #2 with ugly hack like this 
  return (void)some();
Comment 3 Elena Laskavaia CLA 2010-05-22 22:32:51 EDT
Checked implemented. a) and b) from comment above are also corrected.