[cfe-dev] A question about when a defaulted move assignment operator is deleted

ZhangXiongpang zhangxiongpang at gmail.com
Wed May 15 20:42:23 PDT 2013


Platform: linux, x86_84, clang++3.3 (trunk 178517), g++4.7.2

I'm learning C++11 standard, and often write some code to test clang++.
But sometimes I'm not sure whether my understanding is right when clang++
does not work as my expecting.

12.8/p23 in N3290:
--------------------------------------------------------
A defaulted copy/move assignment operator for class X is defined as deleted
if X has:
  ...
  -- for the move assignment operator, a non-static data member or direct
base class with a type that does
     not have a move assignment operator and is not trivially copyable, or
any direct or indirect virtual
     base class.
--------------------------------------------------------
Does it partially mean that the defaulted move assignment operator for class
X is defined as deleted if X has any direct or indirect virtual base class?

If my understanding is right, then the following code shall be ill-formed
(because D::operator=(D&&) is defined as deleted):
--------------------------------------------------------
struct B {};
struct D : virtual B {
    D& operator=(const D&) = delete; // #1
    D& operator=(D&&) = default;     // #2
};
void test() {
    D d1, d2;
    d1 = static_cast<D&&>(d2);  // #3: call D::operator=(D&&)
}
--------------------------------------------------------

But both clang++ and g++ not report error at #3.
I'm not sure whether clang++ doesn't support it or my understanding is
false.



--
View this message in context: http://clang-developers.42468.n3.nabble.com/A-question-about-when-a-defaulted-move-assignment-operator-is-deleted-tp4032130.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list