-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Description
MSVC is implementing a new warning (off-by-default) to detect the following deprecated cases (I've heard that Clang and GCC -Wdeprecated
can also detect this) in N4928 [class.copy.ctor]/6 (emphasis mine):
If the class definition does not explicitly declare a copy constructor, a non-explicit one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy constructor is defined as deleted; otherwise, it is defaulted (9.5). The latter case is deprecated if the class has a user-declared copy assignment operator or a user-declared destructor (D.8).
and [class.copy.assign]/2 (emphasis mine):
If the class definition does not explicitly declare a copy assignment operator, one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy assignment operator is defined as deleted; otherwise, it is defaulted (9.5). The latter case is deprecated if the class has a user-declared copy constructor or a user-declared destructor (D.8).
While cleaning up MSVC's STL (see microsoft/STL#3497), I found the following deprecated implicit copy ctors/assigns in libcxx's test suite:
llvm-project/libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.star/op_star.pass.cpp
(29):- warning C5267: definition of implicit copy constructor for
'A'
is deprecated because it has a user-provided destructor Lines 24 to 33 in 53689fd
class A { int data_; public: A() : data_(1) {} ~A() {data_ = -1;} friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;} };
- warning C5267: definition of implicit copy constructor for
llvm-project/libcxx/test/support/deleter_types.h
(191):- warning C5267: definition of implicit copy constructor for
'CDeleter<A []>'
is deprecated because it has a user-provided destructor llvm-project/libcxx/test/support/deleter_types.h
Lines 181 to 200 in 53689fd
template <class T> class CDeleter<T[]> { int state_; public: TEST_CONSTEXPR_CXX23 CDeleter() : state_(0) {} TEST_CONSTEXPR_CXX23 explicit CDeleter(int s) : state_(s) {} template <class U> TEST_CONSTEXPR_CXX23 CDeleter(const CDeleter<U>& d) : state_(d.state()) {} TEST_CONSTEXPR_CXX23 ~CDeleter() { assert(state_ >= 0); state_ = -1; } TEST_CONSTEXPR_CXX23 int state() const { return state_; } TEST_CONSTEXPR_CXX23 void set_state(int i) { state_ = i; } TEST_CONSTEXPR_CXX23 void operator()(T* p) { delete[] p; } };
- warning C5267: definition of implicit copy constructor for
llvm-project/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_move.pass.cpp
(29):- warning C5267: definition of implicit assignment operator for
'B'
is deprecated because it has a user-provided destructor - warning C5267: definition of implicit copy constructor for
'B'
is deprecated because it has a user-provided destructor llvm-project/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_move.pass.cpp
Lines 26 to 30 in 53689fd
struct B { int id_; explicit B(int i = 0) : id_(i) {} virtual ~B() {} };
- warning C5267: definition of implicit assignment operator for
@CaseyCarter's https://reviews.llvm.org/D144694 fixes other occurrences in any
and optional
's tests.