Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 311268 - [code analysis] does not detect if a return statement has a expression or not
Summary: [code analysis] does not detect if a return statement has a expression or not
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-codan (show other bugs)
Version: 7.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 7.0   Edit
Assignee: Project Inbox CLA
QA Contact: Elena Laskavaia CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-30 22:11 EDT by Felipe CLA
Modified: 2010-07-28 15:26 EDT (History)
1 user (show)

See Also:


Attachments
Proposal to check the returns expressions and report warning accordingly (8.23 KB, patch)
2010-04-30 22:42 EDT, Felipe CLA
elaskavaia.cdt: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.