Skip to content

Unnamed bit field is being compared in defaulted equality operator #61335

@foonathan

Description

@foonathan
#include <cassert>
#include <cstring>

struct foo
{
    int member : 8;
    int : 24;

    bool operator==(const foo&) const = default;
};

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 does not pass?!
    assert(a == b);
}

Demo: https://godbolt.org/z/75ee78Gss

Unnamed bit fields aren't members, so they shouldn't be compared.

Metadata

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions