When synthesizing implicit copy/move constructors and copy/move assignment

operators, don't make an initializer or sub-operation for zero-width
bitfields.




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133221 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
John McCall 2011-06-17 00:18:42 +00:00
Родитель 8d5e18c69e
Коммит b77115d7b9
2 изменённых файлов: 24 добавлений и 5 удалений

Просмотреть файл

@ -1972,6 +1972,11 @@ BuildImplicitMemberInitializer(Sema &SemaRef, CXXConstructorDecl *Constructor,
if (ImplicitInitKind == IIK_Copy) {
ParmVarDecl *Param = Constructor->getParamDecl(0);
QualType ParamType = Param->getType().getNonReferenceType();
// Suppress copying zero-width bitfields.
if (const Expr *Width = Field->getBitWidth())
if (Width->EvaluateAsInt(SemaRef.Context) == 0)
return false;
Expr *MemberExprBase =
DeclRefExpr::Create(SemaRef.Context, NestedNameSpecifierLoc(), Param,
@ -2256,11 +2261,10 @@ Sema::SetDelegatingInitializer(CXXConstructorDecl *Constructor,
return false;
}
bool
Sema::SetCtorInitializers(CXXConstructorDecl *Constructor,
CXXCtorInitializer **Initializers,
unsigned NumInitializers,
bool AnyErrors) {
bool Sema::SetCtorInitializers(CXXConstructorDecl *Constructor,
CXXCtorInitializer **Initializers,
unsigned NumInitializers,
bool AnyErrors) {
if (Constructor->getDeclContext()->isDependentContext()) {
// Just store the initializers as written, they will be checked during
// instantiation.
@ -7011,6 +7015,11 @@ void Sema::DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
Invalid = true;
continue;
}
// Suppress assigning zero-width bitfields.
if (const Expr *Width = Field->getBitWidth())
if (Width->EvaluateAsInt(Context) == 0)
continue;
QualType FieldType = Field->getType().getNonReferenceType();
if (FieldType->isIncompleteArrayType()) {

Просмотреть файл

@ -70,3 +70,13 @@ void test_X2()
pimpl pdata;
pdata.f0( new impl(*i));
}
// rdar://problem/9598341
namespace test3 {
struct A { A(const A&); A&operator=(const A&); };
struct B { A a; unsigned : 0; };
void test(const B &x) {
B y = x;
y = x;
}
}