On 12/16/20 7:10 PM, Martin Sebor via Gcc-patches wrote:
> The -Wmismatched-new-delete detection of operator members of class
> template instantiations is incomplete and overly simplistic, leading
> to incorrect results and false positives. Rather than reinventing
> the wheel and parsing the mangled qualified names of the operators
> the attached patch uses the demangler to compare their names. Since
> the code is only entered rarely (for user- defined overloads of
> the operators, the cost of the demangling should be negligible in
> most code bases).
>
> Tested on x86_64-linux.
>
> Martin
>
> gcc-98305.diff
>
> PR c++/98305 spurious -Wmismatched-new-delete on template instance
>
> gcc/ChangeLog:
>
> PR c++/98305
> * builtins.c (new_delete_mismatch_p): New overload.
> (new_delete_mismatch_p (tree, tree)): Call it.
>
> gcc/testsuite/ChangeLog:
>
> PR c++/98305
> * g++.dg/warn/Wmismatched-new-delete-3.C: New test.
>
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index 28e44445ab2..b1d69855523 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -78,6 +78,7 @@ along with GCC; see the file COPYING3. If not see
> #include "tree-ssa-live.h"
> #include "tree-outof-ssa.h"
> #include "attr-fnspec.h"
> +#include "demangle.h"
>
> struct target_builtins default_target_builtins;
> #if SWITCHABLE_TARGET
> @@ -13053,121 +13054,152 @@ call_dealloc_argno (tree exp)
> return UINT_MAX;
> }
>
> -/* Return true if DELETE_DECL is an operator delete that's not suitable
> - to call with a pointer returned fron NEW_DECL. */
> +/* Return true if DELC doesn't refer to an operator delete that's
> + suitable to call with a pointer returned from the operator new
> + described by NEWC. */
s/DELC/DECL/
OK with the nit fixed.
jeff