[llvm-bugs] [Bug 37295] New: union with zero length array cause compile warning

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Apr 30 07:42:09 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37295

            Bug ID: 37295
           Summary: union with zero length array cause compile warning
           Product: new-bugs
           Version: 3.9
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: ykrocku at gmail.com
                CC: llvm-bugs at lists.llvm.org

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct FooT
{
    uint32_t type;
    uint32_t len;
    union
    {
        uint8_t array[0];
    } u;
    FooT() {
    }
} FooT;

#ifdef __cplusplus
}
#endif

int main(int argc, const char *argv[])
{
    printf("sizeof FooT %zd\n", sizeof(FooT));
    return 0;
}

-----
Compile above code snippet will warns:
main.cpp:14:5: warning: union has size 0 in C, size 1 in C++
[-Wextern-c-compat]
    union

But the runtime result shows sizeof(FooT) is 8:
sizeof FooT 8

Seems like introduce by https://bugs.llvm.org/show_bug.cgi?id=5065

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180430/a4c025c9/attachment.html>


More information about the llvm-bugs mailing list