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

Bug 350168

Summary: false positive for 'no return in function returning non void' with switch statement
Product: [Tools] CDT Reporter: Andrew Eidsness <eclipse>
Component: cdt-codanAssignee: CDT Codan Inbox <cdt-codan-inbox>
Status: RESOLVED FIXED QA Contact: Elena Laskavaia <elaskavaia.cdt>
Severity: normal    
Priority: P3 CC: cdtdoug, matt, yevshif, zeratul976
Version: 8.0   
Target Milestone: 8.5   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Andrew Eidsness CLA 2011-06-23 12:24:13 EDT
Build Identifier: Build id: 20110615-0604

"No return in function returning non-void" reported for the following:

bool func( int i )
{
    switch( i )
    {
    case 0:
        return true;
    default:
        return false;
        break;
    }
}

If I remove the final break statement then the problem goes away.  The break statement is unreachable and therefore totally useless; but it seems to be confusing the checker.

Reproducible: Always
Comment 1 Tomasz Wesolowski CLA 2011-07-28 12:30:51 EDT
Yes, dead code confuses the checker- looks like the same issue as in bug 348386
Comment 2 Matt Hargett CLA 2011-12-20 16:14:12 EST
I am seeing something similar in latest trunk (Build id: 20111215-0110), but I don't think it's necessarily related to dead code:


inline const char *ICAP_Scan_status_to_string(ICAP_Scan_status iss)
{
	switch (iss)
	{
	case ISS_NOT_SCANNED:
		return "ICAP_COMMUNICATION_ERROR";					
	case ISS_NO_MODIFICATION:
		return "ICAP_NO_MODIFICATION";						
	case ISS_REPLACEMENT:
		return "ICAP_REPLACED";								
	case ISS_SCAN_IN_PROGRESS:
		return "ISS_SCAN_IN_PROGRESS";

	case ISS_CORRUPT_UNSCANNED_OBJECT:
		return "ISS_CORRUPT_UNSCANNED_OBJECT";

	default:
		return "unknown";
	}
}

Here, this switch doesn't cover all of the cases in the enum -- the default case isn't dead code (not that I think CODAN is thinking *that* deeply about it ;)). All paths return a value, so this is a false positive.
Comment 3 Elena Laskavaia CLA 2011-12-20 22:32:00 EST
Can you send another bug about this - this seems to be a different issue
Comment 4 Matt Hargett CLA 2011-12-21 18:43:12 EST
Done. https://bugs.eclipse.org/bugs/show_bug.cgi?id=367377
Comment 6 Elena Laskavaia CLA 2014-08-13 09:35:45 EDT
fixed