]> granicus.if.org Git - clang/commitdiff
Correctly ignore unnamed bit-fields when checking whether a union has fields.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 8 Nov 2016 01:07:26 +0000 (01:07 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 8 Nov 2016 01:07:26 +0000 (01:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286189 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/CodeGenCXX/mangle-unnamed.cpp

index fb3b7373978689ea1a059b5906bca0ad5a66ce5e..e96099dab49718a1ce3f5affcb47f74da3296523 100644 (file)
@@ -6657,8 +6657,13 @@ bool SpecialMemberDeletionInfo::shouldDeleteForField(FieldDecl *FD) {
 bool SpecialMemberDeletionInfo::shouldDeleteForAllConstMembers() {
   // This is a silly definition, because it gives an empty union a deleted
   // default constructor. Don't do that.
-  if (CSM == Sema::CXXDefaultConstructor && inUnion() && AllFieldsAreConst &&
-      !MD->getParent()->field_empty()) {
+  if (CSM == Sema::CXXDefaultConstructor && inUnion() && AllFieldsAreConst) {
+    bool AnyFields = false;
+    for (auto *F : MD->getParent()->fields())
+      if ((AnyFields = !F->isUnnamedBitfield()))
+        break;
+    if (!AnyFields)
+      return false;
     if (Diagnose)
       S.Diag(MD->getParent()->getLocation(),
              diag::note_deleted_default_ctor_all_const)
index a62bdd5393c406257e12b905b5cbe3deb2a7bd72..43b7bd79537da30f17c72a92131dc199219a5022 100644 (file)
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin10 | FileCheck %s
+// RUN: %clang_cc1 -std=c++98 -emit-llvm %s -o - -triple=x86_64-apple-darwin10 | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=x86_64-apple-darwin10 | FileCheck %s
 
 struct S {
   virtual ~S() { }