public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/70834] Incorrect warning for placement new when conditionally used
       [not found] <bug-70834-4@http.gcc.gnu.org/bugzilla/>
@ 2021-05-03 21:23 ` msebor at gcc dot gnu.org
  2021-05-18  6:38 ` frankhb1989 at gmail dot com
  1 sibling, 0 replies; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-05-03 21:23 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2017-01-03 00:00:00         |2021-5-3
             Blocks|                            |100399
      Known to fail|8.0                         |11.1.0, 12.0, 8.4.0

--- Comment #7 from Martin Sebor <msebor at gcc dot gnu.org> ---
No change in GCC 11.  This false positive too will be avoided by running
-Wplacement-new later, when the program is in SSA form, rather than in the
front end.


Referenced Bugs:

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

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

* [Bug c++/70834] Incorrect warning for placement new when conditionally used
       [not found] <bug-70834-4@http.gcc.gnu.org/bugzilla/>
  2021-05-03 21:23 ` [Bug c++/70834] Incorrect warning for placement new when conditionally used msebor at gcc dot gnu.org
@ 2021-05-18  6:38 ` frankhb1989 at gmail dot com
  1 sibling, 0 replies; 2+ messages in thread
From: frankhb1989 at gmail dot com @ 2021-05-18  6:38 UTC (permalink / raw)
  To: gcc-bugs

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

frankhb1989 at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |frankhb1989 at gmail dot com

--- Comment #8 from frankhb1989 at gmail dot com ---
(In reply to Martin Sebor from comment #7)
> No change in GCC 11.  This false positive too will be avoided by running
> -Wplacement-new later, when the program is in SSA form, rather than in the
> front end.

Actually worse in GCC 11. Try this case:

#include <cstddef>
#include <cstdlib>
#include <memory>
#include <new>
#include <stdexcept>

struct hdr_t
{
        void* p_block;
};

constexpr auto offset = sizeof(hdr_t) > alignof(hdr_t) ? sizeof(hdr_t) :
alignof(hdr_t);


void* operator new(std::size_t bytes, std::size_t alignment)
{
        auto space(offset + bytes + alignment);
        auto ptr(static_cast<char*>(std::malloc(space)));
        void* p(&ptr[offset]);

        if(std::align(alignment, bytes, p, space))
        {
                (::new(static_cast<void*>(static_cast<char*>(p) - offset))
hdr_t)->p_block = ptr;
        //      (::new(ptr + (std::size_t(static_cast<char*>(p) - ptr)) -
offset) hdr_t)->p_block = ptr;
                return p;
        }
        throw std::bad_alloc();
}

int main()
{}

This is warned in G++ 11.1, but not G++ 10.2.

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

end of thread, other threads:[~2021-05-18  6:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-70834-4@http.gcc.gnu.org/bugzilla/>
2021-05-03 21:23 ` [Bug c++/70834] Incorrect warning for placement new when conditionally used msebor at gcc dot gnu.org
2021-05-18  6:38 ` frankhb1989 at gmail dot com

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).