public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100876] New: -Wmismatched-new-delete should either look through or ignore placement new
@ 2021-06-02 13:46 redbeard0531 at gmail dot com
  2021-06-02 15:19 ` [Bug c++/100876] " redi at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: redbeard0531 at gmail dot com @ 2021-06-02 13:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100876
           Summary: -Wmismatched-new-delete should either look through or
                    ignore placement new
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redbeard0531 at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/KTTMrEGns

Example code:
    free(new (malloc(4)) int()); // Warns but shouldn't
    delete new (malloc(4)) int(); // Doesn't warn but should

output:

<source>:5:9: warning: 'void free(void*)' called on pointer returned from a
mismatched allocation function [-Wmismatched-new-delete]
    5 |     free(new (malloc(4)) int()); // Warns but shouldn't
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~
<source>:5:30: note: returned from 'void* operator new(std::size_t, void*)'
    5 |     free(new (malloc(4)) int()); // Warns but shouldn't
      |                              ^

While it would be nice to have a warning on the second line, not warning on the
first seems more important. And hopefully is a backportable fix.

Here is some Real World Code exhibiting this pattern that g++ currently warns
about when compiling:
https://github.com/facebook/hermes/blob/dfef1abd6d20b196e24c591e225a7003e6337a94/unittests/VMRuntime/StringPrimitiveTest.cpp#L221-L235.
There is also an example using calloc() lower in that file.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-06-17 20:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02 13:46 [Bug c++/100876] New: -Wmismatched-new-delete should either look through or ignore placement new redbeard0531 at gmail dot com
2021-06-02 15:19 ` [Bug c++/100876] " redi at gcc dot gnu.org
2021-06-02 18:16 ` [Bug middle-end/100876] -Wmismatched-new-delete should understand placement new when it's not inlined msebor at gcc dot gnu.org
2021-06-02 18:16 ` msebor at gcc dot gnu.org
2021-06-02 21:42 ` msebor at gcc dot gnu.org
2021-06-14 22:51 ` cvs-commit at gcc dot gnu.org
2021-06-14 22:55 ` [Bug middle-end/100876] [11 Regression] " msebor at gcc dot gnu.org
2021-06-15 18:47 ` cvs-commit at gcc dot gnu.org
2021-06-17 20:08 ` cvs-commit at gcc dot gnu.org
2021-06-17 20:08 ` cvs-commit at gcc dot gnu.org
2021-06-17 20:11 ` msebor at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).