On 8/5/2021 4:02 PM, Martin Sebor via Gcc-patches wrote:
-Wmismatched-new-delete partly relies on valid_new_delete_pair_p()
to detect matching calls to operator new and delete.  The function
returns a conservative result which, when indicating a mismatch,
the warning then works to make more accurate before it triggers.
As it turns out, the logic is inadvertently overly permissive in
the most common case of a mismatch: between the array and scalar
forms of the global operators new and delete such as in:

  delete new int[2];   // should be delete[]

The attached patch solves the problem by adding a new argument to
valid_new_delete_pair_p() for the function to set to indicate when
its negative result is definitive rather than a conservative guess.

Tested on x86_64-linux.

Martin

gcc-101791.diff

Diagnose mismatches between array and scalar new and delete [PR101791].

Resolves:
PR middle-end/101791 - missing warning on a mismatch between scalar and array 
forms of new and delete


gcc/ChangeLog:

        PR middle-end/101791
        * gimple-ssa-warn-access.cc (new_delete_mismatch_p): Use new argument
        to valid_new_delete_pair_p.
        * tree.c (valid_new_delete_pair_p): Add argument.
        * tree.h (valid_new_delete_pair_p): Same.

gcc/testsuite/ChangeLog:

        PR middle-end/101791
        * g++.dg/warn/Wmismatched-new-delete-6.C: New test.
        * g++.dg/warn/Wmismatched-new-delete-7.C: New test.
OK
jeff

Reply via email to