<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - union with zero length array cause compile warning"
href="https://bugs.llvm.org/show_bug.cgi?id=37295">37295</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>union with zero length array cause compile warning
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>3.9
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>ykrocku@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>#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 <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED FIXED - clang/C++: warn when empty struct is used in extern "C""
href="show_bug.cgi?id=5065">https://bugs.llvm.org/show_bug.cgi?id=5065</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>