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

            Bug ID: 90728
           Summary: False positive Wmemset-elt-size with zero size array
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yyc1992 at gmail dot com
  Target Milestone: ---

The code below comes from a template expansion (when certain cache feature is
disabled) and all the operation on the `buff` member are no-op.

```
#include <string.h>

struct A {
    A()
    {
        memset(&buff, 0xff, sizeof(buff));
    }

    int buff[0];
};
```

However, this start to raise a warning on GCC 9

```
a.cpp: In constructor 'A::A()':
a.cpp:8:41: warning: 'memset' used with length equal to number of elements
without multiplication by element size [-Wmemset-elt-size]
    8 |         memset(&buff, 0xff, sizeof(buff));
      |                                         ^
```

It seems that the warning logic simply compare the size (as well as checking
element size != 1) without taking into account the 0 size case.

Reply via email to