[cfe-commits] r133221 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/CodeGenCXX/implicit-copy-constructor.cpp
John McCall
rjmccall at apple.com
Thu Jun 16 17:18:42 PDT 2011
Author: rjmccall
Date: Thu Jun 16 19:18:42 2011
New Revision: 133221
URL: http://llvm.org/viewvc/llvm-project?rev=133221&view=rev
Log:
When synthesizing implicit copy/move constructors and copy/move assignment
operators, don't make an initializer or sub-operation for zero-width
bitfields.
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CodeGenCXX/implicit-copy-constructor.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=133221&r1=133220&r2=133221&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Jun 16 19:18:42 2011
@@ -1972,6 +1972,11 @@
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 @@
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 @@
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()) {
Modified: cfe/trunk/test/CodeGenCXX/implicit-copy-constructor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/implicit-copy-constructor.cpp?rev=133221&r1=133220&r2=133221&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/implicit-copy-constructor.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/implicit-copy-constructor.cpp Thu Jun 16 19:18:42 2011
@@ -70,3 +70,13 @@
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;
+ }
+}
More information about the cfe-commits
mailing list