From 5e052985496b6fd9785024a7c4dacace7cbe4072 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 8 Nov 2016 01:07:26 +0000 Subject: [PATCH] Correctly ignore unnamed bit-fields when checking whether a union has fields. llvm-svn: 286189 --- clang/lib/Sema/SemaDeclCXX.cpp | 9 +++++++-- clang/test/CodeGenCXX/mangle-unnamed.cpp | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index fb3b737..e96099d 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/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/clang/test/CodeGenCXX/mangle-unnamed.cpp b/clang/test/CodeGenCXX/mangle-unnamed.cpp index a62bdd5..43b7bd7 100644 --- a/clang/test/CodeGenCXX/mangle-unnamed.cpp +++ b/clang/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() { } -- 2.7.4