public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109096] New: __has_unique_object_representations does not account for unnamed bitfield
@ 2023-03-10 21:52 gcc at jonathanmueller dot dev
  2023-03-10 22:04 ` [Bug c++/109096] " gcc at jonathanmueller dot dev
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: gcc at jonathanmueller dot dev @ 2023-03-10 21:52 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109096
           Summary: __has_unique_object_representations does not account
                    for unnamed bitfield
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at jonathanmueller dot dev
  Target Milestone: ---

__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:

```
#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 passes; they have the same value representation.
    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/Y4GzqYE8s

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-05-04  7:25 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-10 21:52 [Bug c++/109096] New: __has_unique_object_representations does not account for unnamed bitfield gcc at jonathanmueller dot dev
2023-03-10 22:04 ` [Bug c++/109096] " gcc at jonathanmueller dot dev
2023-03-10 22:21 ` pinskia at gcc dot gnu.org
2023-03-10 22:49 ` jakub at gcc dot gnu.org
2023-03-13 10:03 ` jakub at gcc dot gnu.org
2023-03-14 15:19 ` cvs-commit at gcc dot gnu.org
2023-03-14 15:20 ` jakub at gcc dot gnu.org
2023-03-19  5:31 ` cvs-commit at gcc dot gnu.org
2023-03-20 10:30 ` jakub at gcc dot gnu.org
2023-05-02 20:15 ` cvs-commit at gcc dot gnu.org
2023-05-03 10:43 ` jakub at gcc dot gnu.org
2023-05-03 15:22 ` cvs-commit at gcc dot gnu.org
2023-05-04  7:25 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).