Skip to content

Deprecated implicit copy ctors/assigns in libcxx/test #60977

@StephanTLavavej

Description

@StephanTLavavej

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):
  • 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
    • 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; }
      };
  • llvm-project/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_move.pass.cpp(29):

@CaseyCarter's https://reviews.llvm.org/D144694 fixes other occurrences in any and optional's tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.test-suite

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions