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

            Bug ID: 98158
           Summary: Gcc generates warning about its own generated move
                    assignment operator
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: darklythinking at yahoo dot com
  Target Milestone: ---

Version:
$ gcc --version
gcc (Gentoo 10.2.0-r3 p4) 10.2.0

System:
The bug doesn't happen if no arch is specified but with -march=skylake or
-march=znver2 the warning appears(and probably others but those are the 2 I
tested)

Code:
#include <string>
#include <cstdint>

struct test
{
        std::string a;
        std::uint8_t b[16];
        std::uint8_t c[16];
};

test function(test blah)
{
        blah = {};
        return blah;
}

int main(int argc, char *argv[])
{
        return 0;
}

Output:
$ g++ -O3 -march=skylake test.cpp
In member function ‘test& test::operator=(test&&)’,
    inlined from ‘test function(test)’ at test.cpp:13:10:
test.cpp:4:8: warning: writing 32 bytes into a region of size 16
[-Wstringop-overflow=]
    4 | struct test
      |        ^~~~
test.cpp: In function ‘test function(test)’:
test.cpp:7:15: note: at offset 0 to object ‘test::b’ with size 16 declared here
    7 |  std::uint8_t b[16];
      |               ^


Note that the warning actually happens in a move assignment operator generated
by gcc itself.

The warning also appears if std::vector is used instead of the std::string but
I wasn't able to replace it with a struct or static array of any size and
reproduce the bug that way.

Reply via email to