Bug 38552

Summary: Invalid function return path analysis error report
Product: gcc Reporter: Piotr Wyderski <piotr.wyderski>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: fang, fsm, gcc-bugs, ian, pawel_sikora, pinskia, piotr.wyderski, pmladek, wad, Woebbeking
Priority: P3    
Version: 4.3.1   
Target Milestone: ---   
Host: Windows Vista 64-bit, Core2, GCC 4.3.1 (cygwin) Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Piotr Wyderski 2008-12-17 11:39:10 UTC
The following snippet:

------------8<-------------

#include <memory>

typedef std::auto_ptr<int> v_type;

v_type fn(int v) {

    v_type r(new int(4));

    switch(v) {

        case 1:
        case 2: {

            return v_type(new int(5));

        } break;

        default:

            return r;
    }
}

int main(int argc, char *argv[])
{
    fn(4);
    return 0;
}

------------8<-------------

compiled with:

 g++ -Wall -Werror test.cpp

errornously produces:

error: control reaches end of non-void function

However, clearly, all control flow paths do return some result.
Without the "break" statement the code compiles flawlessly.
Comment 1 Paolo Carlini 2008-12-17 15:31:58 UTC
*** Bug 38555 has been marked as a duplicate of this bug. ***
Comment 2 Andrew Pinski 2008-12-22 02:36:24 UTC

*** This bug has been marked as a duplicate of 20681 ***