diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index d1e51de62105..39d6a575aa2c 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -1555,10 +1555,11 @@ void InitListChecker::CheckStructUnionTypes(const InitializedEntity &Entity, } } - // Value-initialize the first named member of the union. + // Value-initialize the first member of the union that isn't an unnamed + // bitfield. for (RecordDecl::field_iterator FieldEnd = RD->field_end(); Field != FieldEnd; ++Field) { - if (Field->getDeclName()) { + if (!Field->isUnnamedBitfield()) { if (VerifyOnly) CheckEmptyInitializable( InitializedEntity::InitializeMember(*Field, &Entity), diff --git a/clang/test/CodeGenCXX/cxx1y-initializer-aggregate.cpp b/clang/test/CodeGenCXX/cxx1y-initializer-aggregate.cpp index 8bdf8633d61e..098a4b945e04 100644 --- a/clang/test/CodeGenCXX/cxx1y-initializer-aggregate.cpp +++ b/clang/test/CodeGenCXX/cxx1y-initializer-aggregate.cpp @@ -36,6 +36,17 @@ B y {}; B z { 1 }; // CHECK: @z = global {{.*}} { i32 1 } +// Brace initialization should initialize the first field even though it is +// unnamed. +union C { + struct { + int C::*memptr; + }; +}; + +C n{}; +// CHECK: @n = global %union.C { %struct.anon { i64 -1 } }, align 8 + // Initialization of 'a': // CHECK: store i32 0, i32* getelementptr inbounds ({{.*}} @a, i32 0, i32 0)