Skip to content

Commit 183b6b5

Browse files
committed
[clang][Interp] Ignore unnamed bitfields when checking init
Unnamed bitfields need to be ignored here.
1 parent b98e6a5 commit 183b6b5

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

clang/lib/AST/Interp/EvaluationResult.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ static bool CheckFieldsInitialized(InterpState &S, SourceLocation Loc,
105105
Result &= CheckFieldsInitialized(S, Loc, FieldPtr, FieldPtr.getRecord());
106106
} else if (FieldType->isIncompleteArrayType()) {
107107
// Nothing to do here.
108+
} else if (F.Decl->isUnnamedBitfield()) {
109+
// Nothing do do here.
108110
} else if (FieldType->isArrayType()) {
109111
const auto *CAT =
110112
cast<ConstantArrayType>(FieldType->getAsArrayTypeUnsafe());

clang/test/AST/Interp/cxx20.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,3 +776,26 @@ namespace RewrittenBinaryOperators {
776776
};
777777
static_assert(X() < X(), "");
778778
}
779+
780+
namespace GH61417 {
781+
struct A {
782+
unsigned x : 1;
783+
unsigned : 0;
784+
unsigned y : 1;
785+
786+
constexpr A() : x(0), y(0) {}
787+
bool operator==(const A& rhs) const noexcept = default;
788+
};
789+
790+
void f1() {
791+
constexpr A a, b;
792+
constexpr bool c = (a == b); // no diagnostic, we should not be comparing the
793+
// unnamed bit-field which is indeterminate
794+
}
795+
796+
void f2() {
797+
A a, b;
798+
bool c = (a == b); // no diagnostic nor crash during codegen attempting to
799+
// access info for unnamed bit-field
800+
}
801+
}

0 commit comments

Comments
 (0)