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

            Bug ID: 100370
           Summary: [11.1.0 regression] Incorrect warning for placement
                    new
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: foldy at rmki dot kfki.hu
  Target Milestone: ---

With g++ 11.1.0:

tmp> cat test.cc
#include <new>

int main()
{
  struct s1 { int iv[4]; };
  struct s2 { union { char* cp; int* ip; }; };

  s2 b;
  b.ip=new int[8];
  new (b.ip+4) s1;
}
tmp> g++ -c test.cc
test.cc: In function 'int main()':
test.cc:10:12: warning: placement new constructing an object of type
'main()::s1' and size '16' in a region of type 'main()::s2' and size '0'
[-Wplacement-new=]
   10 |   new (b.ip+4) s1;
      |        ~~~~^~
test.cc:8:6: note: at offset 16 from 'b' declared here
    8 |   s2 b;
      |      ^

g++ 10.2.1 is OK.

Reply via email to