<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61336>61336</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
__has_unique_object_representations does not account for unnamed bitfield
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
foonathan
</td>
</tr>
</table>
<pre>
__has_unique_object_representations should return false for types that contain an unnamed bit field of non-zero bit-width, since that introduces padding bits; yet it doesn't:
```cpp
#include <cassert>
#include <cstring>
struct foo
{
int member : 8;
// We explitly introduce 24 padding bits here.
int : 24;
bool operator==(const foo&) const = default;
};
// Yet this assertion passes?!
static_assert(__has_unique_object_representations(foo));
// But we clearly don't have unique object representations:
int main()
{
// Create two objects with different object representations.
foo a, b;
std::memset(&a, 0xFF, sizeof(foo));
std::memset(&b, 0x99, sizeof(foo));
// Make all members identical to give them the same value representation.
a.member = 0;
b.member = 0;
// This should pass, but doesn't due to #61335.
// assert(a == b);
// But this fails; they don't have unique object representations!
assert(std::memcmp(&a, &b, sizeof(foo)) == 0);
}
```
https://godbolt.org/z/MG73MTffb
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVc1y6ygTfRq86YpLBvlHCy2S-NO3yu5WTc3KhaBlMYNAA63kOk8_hSTHP0lm7lRRWAZ0-nSfI1rGaI4OsWTrJ7beL-RArQ9l472T1Eq3qL0-lYdDK-NhcOavAQ--_gMVHQL2ASM6kmS8ixBbP1gNAWkIDhppI0LjA9CpxwjUSgLlHUnjQDoYnJMdaqgNQWPQavANOO8e3jH4tPrwZjS1jD9DNE7hBGAcBa8HhRF6qbVxx3Q0MvEEJyQwBNpjdIxviYlHlu1Zdp432TRU388rXBin7KARmHhWMkYMxMT_vtyNFIw7XnbHOVIYFEHj_by6fZoeACBRhQ67GgMw8Qg7Jq42Ga8Yr-A3BPzZW0P2dEkNeH6THLQYcHkLnB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