public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96511] New: Incorrect placement-new warning
@ 2020-08-06 23:46 mserdarsanli at gmail dot com
  2020-08-07 14:50 ` [Bug c++/96511] " msebor at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: mserdarsanli at gmail dot com @ 2020-08-06 23:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96511
           Summary: Incorrect placement-new warning
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mserdarsanli at gmail dot com
  Target Milestone: ---

Below code causes the warning in the last line, which seems to be incorrect. It
affects all versions starting from GCC 8
Compiler explorer: https://godbolt.org/z/xhf6cr

#include <new>

struct Foo {
    Foo() = default;
    Foo(int _a) : a(_a) {}
    int a = 0;
};

void f()
{
    Foo arr[2];

    new (arr) Foo(10); // ok
    new (arr + 0) Foo(10); // ok
    new (&arr[0]) Foo(10); // ok

    new (&arr[1]) Foo(15); // ok
    new (arr + 1) Foo(15); // warning: placement new constructing an object of
type 'Foo' and size '4' in a region of type 'Foo [2]' and size '0'
[-Wplacement-new=]
}

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

end of thread, other threads:[~2021-01-19 23:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-06 23:46 [Bug c++/96511] New: Incorrect placement-new warning mserdarsanli at gmail dot com
2020-08-07 14:50 ` [Bug c++/96511] " msebor at gcc dot gnu.org
2020-08-11 16:20 ` msebor at gcc dot gnu.org
2020-10-12 15:07 ` cvs-commit at gcc dot gnu.org
2020-10-12 15:08 ` msebor at gcc dot gnu.org
2021-01-19 23:31 ` 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).