Skip to content

Commit

Permalink
[clang][Interp] Ignore unnamed bitfields when checking init
Browse files Browse the repository at this point in the history
Unnamed bitfields need to be ignored here.
  • Loading branch information
tbaederr committed Feb 27, 2024
1 parent b98e6a5 commit 183b6b5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/lib/AST/Interp/EvaluationResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ static bool CheckFieldsInitialized(InterpState &S, SourceLocation Loc,
Result &= CheckFieldsInitialized(S, Loc, FieldPtr, FieldPtr.getRecord());
} else if (FieldType->isIncompleteArrayType()) {
// Nothing to do here.
} else if (F.Decl->isUnnamedBitfield()) {
// Nothing do do here.
} else if (FieldType->isArrayType()) {
const auto *CAT =
cast<ConstantArrayType>(FieldType->getAsArrayTypeUnsafe());
Expand Down
23 changes: 23 additions & 0 deletions clang/test/AST/Interp/cxx20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,3 +776,26 @@ namespace RewrittenBinaryOperators {
};
static_assert(X() < X(), "");
}

namespace GH61417 {
struct A {
unsigned x : 1;
unsigned : 0;
unsigned y : 1;

constexpr A() : x(0), y(0) {}
bool operator==(const A& rhs) const noexcept = default;
};

void f1() {
constexpr A a, b;
constexpr bool c = (a == b); // no diagnostic, we should not be comparing the
// unnamed bit-field which is indeterminate
}

void f2() {
A a, b;
bool c = (a == b); // no diagnostic nor crash during codegen attempting to
// access info for unnamed bit-field
}
}

0 comments on commit 183b6b5

Please sign in to comment.