]> granicus.if.org Git - clang/commitdiff
PR28978: If we need overload resolution for the move constructor of an
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 16 Aug 2016 00:13:47 +0000 (00:13 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 16 Aug 2016 00:13:47 +0000 (00:13 +0000)
anonymous union member of a class, we need overload resolution for the move
constructor of the class itself too; we can't rely on Sema to do the right
thing for us for anonymous union types.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@278763 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclCXX.cpp
test/CXX/special/class.copy/p11.0x.move.cpp

index 7e85619c819a1a8b0d9e0ec03a64aad14c0ca496..7395db586be5aaa25e481c476d49fac594577e61 100644 (file)
@@ -807,6 +807,17 @@ void CXXRecordDecl::addedMember(Decl *D) {
             data().DefaultedDestructorIsDeleted = true;
         }
 
+        // For an anonymous union member, our overload resolution will perform
+        // overload resolution for its members.
+        if (Field->isAnonymousStructOrUnion()) {
+          data().NeedOverloadResolutionForMoveConstructor |=
+              FieldRec->data().NeedOverloadResolutionForMoveConstructor;
+          data().NeedOverloadResolutionForMoveAssignment |=
+              FieldRec->data().NeedOverloadResolutionForMoveAssignment;
+          data().NeedOverloadResolutionForDestructor |=
+              FieldRec->data().NeedOverloadResolutionForDestructor;
+        }
+
         // C++0x [class.ctor]p5:
         //   A default constructor is trivial [...] if:
         //    -- for all the non-static data members of its class that are of
index 514817d2b71c7fdf4bd1daa49db8b33af4728291..ab4259548e741a657ce10a27567720098e26ec85 100644 (file)
@@ -4,6 +4,9 @@ struct Trivial {};
 struct NonTrivial {
   NonTrivial(NonTrivial&&); // expected-note{{copy constructor is implicitly deleted}}
 };
+struct DeletedCopy {
+  DeletedCopy(const DeletedCopy&) = delete;
+};
 
 // A defaulted move constructor for a class X is defined as deleted if X has:
 
@@ -22,6 +25,15 @@ struct DeletedNTVariant2 {
 };
 DeletedNTVariant2::DeletedNTVariant2(DeletedNTVariant2&&) = default; // expected-error{{would delete}}
 
+// Note, move constructor is not a candidate because it is deleted.
+template<typename T> struct DeletedNTVariant3 { // expected-note 2{{default}} expected-note 2{{copy}}
+  union {
+    T NT;
+  };
+};
+extern DeletedNTVariant3<NonTrivial> dntv3a(0); // expected-error {{no matching}}
+extern DeletedNTVariant3<DeletedCopy> dntv3a(0); // expected-error {{no matching}}
+
 // -- a non-static data member of class type M (or array thereof) that cannot be
 //    copied because overload resolution results in an ambiguity or a function
 //    that is deleted or inaccessible