From: Richard Smith Date: Thu, 20 Oct 2016 18:29:25 +0000 (+0000) Subject: [c++1z] Fix assertion failure when using the wrong number of bindings for a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e02feb3964e30644b8e3156807ac431fe244c9c7;p=clang [c++1z] Fix assertion failure when using the wrong number of bindings for a struct with unnamed bitfields. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284761 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index f86b793df5..c1938d5e8e 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -1279,7 +1279,9 @@ static bool checkMemberDecomposition(Sema &S, ArrayRef Bindings, DecompType.getQualifiers()); auto DiagnoseBadNumberOfBindings = [&]() -> bool { - unsigned NumFields = std::distance(RD->field_begin(), RD->field_end()); + unsigned NumFields = + std::count_if(RD->field_begin(), RD->field_end(), + [](FieldDecl *FD) { return !FD->isUnnamedBitfield(); }); assert(Bindings.size() != NumFields); S.Diag(Src->getLocation(), diag::err_decomp_decl_wrong_number_bindings) << DecompType << (unsigned)Bindings.size() << NumFields diff --git a/test/SemaCXX/cxx1z-decomposition.cpp b/test/SemaCXX/cxx1z-decomposition.cpp index 12c863c8c3..762dd7b94d 100644 --- a/test/SemaCXX/cxx1z-decomposition.cpp +++ b/test/SemaCXX/cxx1z-decomposition.cpp @@ -47,4 +47,10 @@ void enclosing() { (void) [n] {}; // expected-error {{'n' in capture list does not name a variable}} } +void bitfield() { + struct { int a : 3, : 4, b : 5; } a; + auto &[x, y] = a; + auto &[p, q, r] = a; // expected-error {{decomposes into 2 elements, but 3 names were provided}} +} + // FIXME: by-value array copies