]> git.ipfire.org Git - thirdparty/gcc.git/commit
warn-access: ignore template parameters when matching operator new/delete [PR109224]
authorArsen Arsenović <arsen@aarsen.me>
Thu, 1 Aug 2024 15:38:15 +0000 (17:38 +0200)
committerArsen Arsenović <arsen@gcc.gnu.org>
Sat, 21 Dec 2024 19:52:13 +0000 (20:52 +0100)
commit7d83a32aacd6005c0c038c74562e35d70f6a77a8
tree72742da9ae59a8b6eb189da4c08c38e26de01c50
parentd637e6d069ade775a4b61f51fff61fe4cce01c36
warn-access: ignore template parameters when matching operator new/delete [PR109224]

Template parameters on a member operator new cannot affect its member
status nor whether it is a singleton or array operator new, hence, we
can ignore it for purposes of matching.  Similar logic applies to the
placement operator delete.

In the PR (and a lot of idiomatic coroutine code generally), operator
new is templated in order to be able to inspect (some of) the arguments
passed to the coroutine, to make allocation-related decisions.  However,
the coroutine implementation will not call a placement delete form, so
it cannot get templated.  As a result, when demangling, we have an extra
template DEMANGLE_COMPONENT_TEMPLATE around the actual operator new, but
not operator delete.  This terminates new_delete_mismatch_p early.

PR middle-end/109224 - Wmismatched-new-delete false positive with a templated operator new (common with coroutines)

gcc/ChangeLog:

PR middle-end/109224
* gimple-ssa-warn-access.cc (new_delete_mismatch_p): Strip
DEMANGLE_COMPONENT_TEMPLATE from the operator new and operator
after demangling.

gcc/testsuite/ChangeLog:

PR middle-end/109224
* g++.dg/warn/Wmismatched-new-delete-9.C: New test.
gcc/gimple-ssa-warn-access.cc
gcc/testsuite/g++.dg/warn/Wmismatched-new-delete-9.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/pr109224.C [new file with mode: 0644]