Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 367377 - false positive for 'no return from non-void function' where a switch has a default case
Summary: false positive for 'no return from non-void function' where a switch has a de...
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-codan (show other bugs)
Version: 8.0   Edit
Hardware: PC Linux
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: CDT Codan Inbox CLA
QA Contact: Elena Laskavaia CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-21 18:42 EST by Matt Hargett CLA
Modified: 2016-12-22 18:48 EST (History)
5 users (show)

See Also:


Attachments
Code Analysis Settings (126.38 KB, image/jpeg)
2012-01-28 10:37 EST, Saifudheen AA CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Hargett CLA 2011-12-21 18:42:34 EST
Build Identifier: Build id: 20111215-0110

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.

Created in a new bug, as requested in comments to bug #350168.

Reproducible: Always
Comment 1 Saifudheen AA CLA 2012-01-28 10:37:15 EST
Created attachment 210231 [details]
Code Analysis Settings
Comment 2 Saifudheen AA CLA 2012-01-28 10:40:00 EST
I do have the same problem.

Eclipse IDE for C/C++ Developers

Version: Indigo Service Release 1
Build id: 20110916-0149
Comment 3 Nathan Ridge CLA 2012-11-17 17:25:59 EST
The given test case is incomplete because it does not include the definition of ICAP_Scan_status.

I tried to reproduce the error by making up a definition for it, adding some other values in the enumeration beyond what is used in the switch statement. However, I am getting no warning with this with Juno:


enum ICAP_Scan_status 
{
    ISS_NOT_SCANNED, 
    ISS_NO_MODIFICATION, 
    ISS_REPLACEMENT, 
    ISS_SCAN_IN_PROGRESS, 
    ISS_CORRUPT_UNSCANNED_OBJECT, 
    SOME_OTHER_VALUE1,
    SOME_OTHER_VALUE2
};

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";
    }
}


Do you still see a warning in Juno? If so, could you please post a complete testcase?
Comment 4 Alexey Alexey CLA 2015-04-22 09:08:43 EDT
Reproduced in Luna (4.4.0). Example:

enum
{
  OK = 100,
  WARNINGS = 200,  
};

int TestCase(int completionStatus)
{
  switch (completionStatus)
  {
  case OK: return 0;
  case WARNINGS: return 1;
  default: return 2;
  };
}
Comment 5 Nathan Ridge CLA 2015-05-12 17:42:20 EDT
I can reproduce the warning in comment 4 in 4.4.0, but not in a recent nightly build, suggesting that the problem was fixed (possibly in bug 455828).
Comment 6 Alexey Alexey CLA 2015-07-01 04:01:55 EDT
Checked in Mars. Bug fixed.
Comment 7 Nathan Ridge CLA 2016-12-22 18:48:22 EST
Closing per comment 6.