[Bug c++/90629] Support for -Wmismatched-new-delete

dcb314 at hotmail dot com gcc-bugzilla@gcc.gnu.org
Thu Aug 27 07:51:18 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90629

David Binderman <dcb314 at hotmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dcb314 at hotmail dot com

--- Comment #2 from David Binderman <dcb314 at hotmail dot com> ---

Here is a little test case:

// bad alloc & dealloc

# include <stdlib.h>

void
f()
{
        char * p = new char [ 10];
        delete p;

        char * p2 = new char;
        delete [] p2;

        char * q = new char [ 10];
        free( q);

        char * q2 = (char *) malloc( 10);
        delete [] q2;
}

Latest gcc finds no problems, latest clang finds two, for p and p2.
q and q2 not found.

Interestingly, I've just started compiling all of fedora distribution
with clang. I've only compiled [a-d]*.spec files so far, but I have 34 cases
found already. This implies about 220 cases in fedora.

So only duplicating what does clang for new and delete would find hundreds of
bugs in fedora. I'd be glad to help with testing any prototype implementation.


More information about the Gcc-bugs mailing list