From: Richard Smith Date: Tue, 8 Nov 2016 01:07:26 +0000 (+0000) Subject: Correctly ignore unnamed bit-fields when checking whether a union has fields. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=71e7eb6af6aefb1482ae1d5accab63efb911907d;p=clang Correctly ignore unnamed bit-fields when checking whether a union has fields. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286189 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index fb3b737397..e96099dab4 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -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) diff --git a/test/CodeGenCXX/mangle-unnamed.cpp b/test/CodeGenCXX/mangle-unnamed.cpp index a62bdd5393..43b7bd7953 100644 --- a/test/CodeGenCXX/mangle-unnamed.cpp +++ b/test/CodeGenCXX/mangle-unnamed.cpp @@ -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() { }