[Bug middle-end/100876] -Wmismatched-new-delete should understand placement new when it's not inlined

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Jun 2 18:16:40 GMT 2021


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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |100406
      Known to fail|                            |11.1.0
            Summary|-Wmismatched-new-delete     |-Wmismatched-new-delete
                   |should either look through  |should understand placement
                   |or ignore placement new     |new when it's not inlined
                 CC|                            |msebor at gcc dot gnu.org
          Component|c++                         |middle-end

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
[Please include all the information we ask for in the bug report, including the
command line options and the full test cases: https://gcc.gnu.org/bugs/#need]

The test case behaves as expected when the placement new is inlined, either
with optimization or when the operator is declared with attribute
always_inline:

  inline __attribute__ ((__always_inline__)) void*
  operator new (__SIZE_TYPE__, void*);

The problem is a general one, not specific to -Wmismatched-new-delete: GCC
understands the semantics of built-in functions, including whether they return
one of their arguments, but not user-defined ones.  Even though it's special,
GCC treats placement new as an ordinary user-defined function.  Because nothing
indicates the operator returns its pointer argument, no logic in GCC can
determine that unless the operator is inlined.

The fix is to either hardcode into GCC the knowledge of placement new, or
provide an attribute for users (and the standard library) to indicate that a
function returns one of its argument.  The former might be suitable for GCC 11
as a bug fix for this warning, the latter is something I'd like to do in GCC 12
regardless.  Let me work on the former and plan on looking into the latter in
the future.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100406
[Bug 100406] bogus/missing -Wmismatched-new-delete


More information about the Gcc-bugs mailing list