<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 - Zero-width bit-field in an anonymous subobject"
href="https://bugs.llvm.org/show_bug.cgi?id=40809">40809</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Zero-width bit-field in an anonymous subobject
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</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>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>aaron@aaronballman.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>I believe the following structure has the incorrect layout according to the C
standard:
struct S {
int i : 1;
union {
int : 0;
};
int j : 1;
};
int main(void) {
return sizeof(struct S) == sizeof(int);
}
main() should return 0, but in Clang it returns 1.
C17 6.7.2.1p13 makes it clear that the members of the anonymous union are
members of the enclosing struct, so the zero-width bit-field should introduce
an allocation boundary via p12.
FWIW, Clang matches GCC's behavior here, but not MSVC's behavior.
I believe this is an instance where the behavior in C and C++ have diverged,
because [class.union.anon]p1 (<a href="http://eel.is/c++draft/class.union.anon#1">http://eel.is/c++draft/class.union.anon#1</a>) says
that the anonymous union members are only members of the containing object for
purposes of name lookup.</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>