Skip to content

Commit 8d908b8

Browse files
authored
[clang][Interp] Ignore unnamed bitfields when zeroing records (#102749)
Including unions, where this is more important.
1 parent 1c26992 commit 8d908b8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

clang/lib/AST/Interp/Compiler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3356,6 +3356,9 @@ bool Compiler<Emitter>::visitZeroRecordInitializer(const Record *R,
33563356
assert(R);
33573357
// Fields
33583358
for (const Record::Field &Field : R->fields()) {
3359+
if (Field.Decl->isUnnamedBitField())
3360+
continue;
3361+
33593362
const Descriptor *D = Field.Desc;
33603363
if (D->isPrimitive()) {
33613364
QualType QT = D->getType();

clang/test/AST/Interp/unions.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,5 +297,13 @@ namespace Zeroing {
297297
static_assert(u6.a[4] == 0, "");
298298
static_assert(u6.b == 0, ""); // both-error {{not an integral constant expression}} \
299299
// both-note {{read of member 'b' of union with active member 'a'}}
300+
301+
union UnionWithUnnamedBitfield {
302+
int : 3;
303+
int n;
304+
};
305+
static_assert(UnionWithUnnamedBitfield().n == 0, "");
306+
static_assert(UnionWithUnnamedBitfield{}.n == 0, "");
307+
static_assert(UnionWithUnnamedBitfield{1}.n == 1, "");
300308
}
301309
#endif

0 commit comments

Comments
 (0)