c++/7430: if method signature lies "I return SomeClass by value" but actually there is no 'return' then construct-destruct asymmetry results!

dh@digitalbrain.com dh@digitalbrain.com
Mon Jul 29 05:26:00 GMT 2002


>Number:         7430
>Category:       c++
>Synopsis:       if method signature lies "I return SomeClass by value" but actually there is no 'return' then construct-destruct asymmetry results!
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 29 04:06:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     dh@digitalbrain.com
>Release:        unknown-1.0
>Organization:
>Environment:
// BUG IN THIS VERSION OF GCC:
// Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
// gcc version 2.95.4 20011002 (Debian prerelease)
// RUNNING UNDER:
// Linux fee 2.4.18 #1 SMP Tue May 21 10:16:05 BST 2002 i686 unknown
>Description:
see How-To-Repeat
>How-To-Repeat:
try this prog:

// BUG IN THIS VERSION OF GCC:
// Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
// gcc version 2.95.4 20011002 (Debian prerelease)
// RUNNING UNDER:
// Linux fee 2.4.18 #1 SMP Tue May 21 10:16:05 BST 2002 i686 unknown

struct X {
    char* m_;
    X() : m_(new char[5]) {}
    ~X() { delete[] m_; }
};

struct C {
    X MightReturnCheese() {
        //
        // INSTRUCTIONS:
        // comment-out the following line and get
        // no compiler error/warning - just a program that
        // returns uninitted-RAM as an "instance" of X. Scary.
        return X();
    }

    void CallIt() {
        MightReturnCheese();
    }
};

int main() {
    C c;
    c.CallIt();
    return 0;
}

>Fix:
none known
(though you can pick up the resulting dangerous code
 that's generated using something like valgrind)
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list