reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
// RUN: %clang_cc1 -verify %s -std=c++11 -Wno-defaulted-function-deleted

struct Trivial {};

template<typename T> struct CopyAssign {
  static T t;
  void test() {
    t = t; // expected-error +{{deleted}}
  }
};
template<typename T> struct MoveAssign {
  static T t;
  void test() {
    // Overload resolution will ignore a defaulted, deleted move assignment,
    // so check for it in a different way.
    T &(T::*f)(T&&) = &T::operator=; // expected-error +{{deleted}}
  }
};
template<typename T> struct MoveOrCopyAssign {
  static T t;
  void test() {
    t = static_cast<T&&>(t); // expected-error +{{copy assignment operator is implicitly deleted}}
  }
};

struct NonTrivialCopyAssign {
  NonTrivialCopyAssign &operator=(const NonTrivialCopyAssign &);
};
struct NonTrivialMoveAssign {
  NonTrivialMoveAssign &operator=(NonTrivialMoveAssign &&);
};
struct AmbiguousCopyAssign {
  AmbiguousCopyAssign &operator=(const AmbiguousCopyAssign &) volatile;
  AmbiguousCopyAssign &operator=(const AmbiguousCopyAssign &) const;
};
struct AmbiguousMoveAssign {
  AmbiguousMoveAssign &operator=(const AmbiguousMoveAssign &&);
  AmbiguousMoveAssign &operator=(volatile AmbiguousMoveAssign &&);
};
struct DeletedCopyAssign {
  DeletedCopyAssign &operator=(const DeletedCopyAssign &) = delete; // expected-note 2{{deleted}}
};
struct DeletedMoveAssign {
  DeletedMoveAssign &operator=(DeletedMoveAssign &&) = delete; // expected-note 2{{deleted}}
};
class InaccessibleCopyAssign {
  InaccessibleCopyAssign &operator=(const InaccessibleCopyAssign &);
};
class InaccessibleMoveAssign {
  InaccessibleMoveAssign &operator=(InaccessibleMoveAssign &&);
};
class NonConstCopyAssign {
  NonConstCopyAssign &operator=(NonConstCopyAssign &);
};

// A defaulted copy/move assignment operator for class X is defined as deleted
// if X has:

//   -- a variant member with a non-trivial corresponding assignment operator
//      and X is a union-like class
struct A1 {
  union {
    NonTrivialCopyAssign x; // expected-note {{variant field 'x' has a non-trivial copy assign}}
  };
};
template struct CopyAssign<A1>; // expected-note {{here}}

struct A2 {
  A2 &operator=(A2 &&) = default; // expected-note {{here}}
  union {
    NonTrivialMoveAssign x; // expected-note {{variant field 'x' has a non-trivial move assign}}
  };
};
template struct MoveAssign<A2>; // expected-note {{here}}

//   -- a non-static const data member of (array of) non-class type
struct B1 {
  const int a; // expected-note 2{{field 'a' is of const-qualified type}}
};
struct B2 {
  const void *const a[3][9][2]; // expected-note 2{{field 'a' is of const-qualified type 'const void *const [3][9][2]'}}
};
struct B3 {
  const void *a[3];
};
template struct CopyAssign<B1>; // expected-note {{here}}
template struct MoveAssign<B1>; // expected-note {{here}}
template struct CopyAssign<B2>; // expected-note {{here}}
template struct MoveAssign<B2>; // expected-note {{here}}
template struct CopyAssign<B3>;
template struct MoveAssign<B3>;

//   -- a non-static data member of reference type
struct C1 {
  int &a; // expected-note 2{{field 'a' is of reference type 'int &'}}
};
template struct CopyAssign<C1>; // expected-note {{here}}
template struct MoveAssign<C1>; // expected-note {{here}}

//   -- a non-static data member of class type M that cannot be copied/moved
struct D1 {
  AmbiguousCopyAssign a; // expected-note {{field 'a' has multiple copy}}
};
struct D2 {
  D2 &operator=(D2 &&) = default; // expected-note {{here}} expected-note {{copy assignment operator is implicitly deleted}}
  AmbiguousMoveAssign a; // expected-note {{field 'a' has multiple move}}
};
struct D3 {
  DeletedCopyAssign a; // expected-note {{field 'a' has a deleted copy}}
};
struct D4 {
  D4 &operator=(D4 &&) = default; // expected-note {{here}} expected-note {{copy assignment operator is implicitly deleted}}
  DeletedMoveAssign a; // expected-note {{field 'a' has a deleted move}}
};
struct D5 {
  InaccessibleCopyAssign a; // expected-note {{field 'a' has an inaccessible copy}}
};
struct D6 {
  D6 &operator=(D6 &&) = default; // expected-note {{here}} expected-note {{copy assignment operator is implicitly deleted}}
  InaccessibleMoveAssign a; // expected-note {{field 'a' has an inaccessible move}}
};
struct D7 {
  const Trivial a; // expected-note 3{{field 'a' has no }}
};
struct D8 {
  volatile Trivial a; // expected-note 3{{field 'a' has no }}
};
template struct CopyAssign<D1>; // expected-note {{here}}
template struct MoveAssign<D2>; // expected-note {{here}}
template struct MoveOrCopyAssign<D2>; // expected-note {{here}}
template struct CopyAssign<D3>; // expected-note {{here}}
template struct MoveAssign<D4>; // expected-note {{here}}
template struct MoveOrCopyAssign<D4>; // expected-note {{here}}
template struct CopyAssign<D5>; // expected-note {{here}}
template struct MoveAssign<D6>; // expected-note {{here}}
template struct MoveOrCopyAssign<D6>; // expected-note {{here}}
template struct CopyAssign<D7>; // expected-note {{here}}
template struct MoveAssign<D7>; // expected-note {{here}}
template struct MoveOrCopyAssign<D7>; // expected-note {{here}}
template struct CopyAssign<D8>; // expected-note {{here}}
template struct MoveAssign<D8>; // expected-note {{here}}
template struct MoveOrCopyAssign<D8>; // expected-note {{here}}

//   -- a direct or virtual base that cannot be copied/moved
struct E1 : AmbiguousCopyAssign {}; // expected-note {{base class 'AmbiguousCopyAssign' has multiple copy}}
struct E2 : AmbiguousMoveAssign { // expected-note {{base class 'AmbiguousMoveAssign' has multiple move}}
  E2 &operator=(E2 &&) = default; // expected-note {{here}}
};
struct E3 : DeletedCopyAssign {}; // expected-note {{base class 'DeletedCopyAssign' has a deleted copy}}
struct E4 : DeletedMoveAssign { // expected-note {{base class 'DeletedMoveAssign' has a deleted move}}
  E4 &operator=(E4 &&) = default; // expected-note {{here}}
};
struct E5 : InaccessibleCopyAssign {}; // expected-note {{base class 'InaccessibleCopyAssign' has an inaccessible copy}}
struct E6 : InaccessibleMoveAssign { // expected-note {{base class 'InaccessibleMoveAssign' has an inaccessible move}}
  E6 &operator=(E6 &&) = default; // expected-note {{here}}
};
template struct CopyAssign<E1>; // expected-note {{here}}
template struct MoveAssign<E2>; // expected-note {{here}}
template struct CopyAssign<E3>; // expected-note {{here}}
template struct MoveAssign<E4>; // expected-note {{here}}
template struct CopyAssign<E5>; // expected-note {{here}}
template struct MoveAssign<E6>; // expected-note {{here}}

namespace PR13381 {
  struct S {
    S &operator=(const S&);
    S &operator=(const volatile S&) volatile = delete; // expected-note{{deleted here}}
  };
  struct T {
    volatile S s; // expected-note{{field 's' has a deleted copy assignment}}
  };
  void g() {
    T t;
    t = T(); // expected-error{{object of type 'PR13381::T' cannot be assigned because its copy assignment operator is implicitly deleted}}
  }
}

namespace Mutable {
  struct AmbiguousCopyAssign {
    AmbiguousCopyAssign &operator=(const AmbiguousCopyAssign &);
    AmbiguousCopyAssign &operator=(volatile AmbiguousCopyAssign &);
  };
  struct X {
    AmbiguousCopyAssign a;
  };
  struct Y {
    mutable AmbiguousCopyAssign a; // expected-note {{multiple copy assignment operators}}
  };
}
template struct CopyAssign<Mutable::X>;
template struct CopyAssign<Mutable::Y>; // expected-note {{here}}