]> granicus.if.org Git - clang/commitdiff
[c++1z] Fix assertion failure when using the wrong number of bindings for a
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 20 Oct 2016 18:29:25 +0000 (18:29 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 20 Oct 2016 18:29:25 +0000 (18:29 +0000)
struct with unnamed bitfields.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284761 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/cxx1z-decomposition.cpp

index f86b793df570070898ef17502d9265befa5fd63a..c1938d5e8e63a111d8373bea33594f5d78a21132 100644 (file)
@@ -1279,7 +1279,9 @@ static bool checkMemberDecomposition(Sema &S, ArrayRef<BindingDecl*> 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
index 12c863c8c3f814f2aa7c5cef2a3e8df2117b7fb2..762dd7b94de34aa22153d9a305aabaa32dece07b 100644 (file)
@@ -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