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

            Bug ID: 117256
           Summary: When initializing an object, padding bits are not set
                    to zero
           Product: gcc
           Version: 14.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: qurong at ios dot ac.cn
  Target Milestone: ---

For this program:


```
#include <cstring>
#include <new>
#include <iostream>

struct A
{
    char c;
    int i;
};

int main()
{
    char mem[sizeof(A)]; 
    std::memset(mem, 1, sizeof(mem));
    new(mem) A();
    for (int i : mem)
        std::cout << i << ", ";
    return 0;
}
```

The 15th line ``new (mem) A();" should have performed value-initialization on
this A object. According to the rules of value-initialization, since the
default constructor of A is generated by the compiler, value-initialization
should first execute zero-initialization, which should set all padding bits to
zero. However, the output result shows that padding bits have not been set to
zero.

Compiler Explorer link: https://godbolt.org/z/TxPddcKzf

Reply via email to