mercredi 22 août 2018

Warning when an explicitly defaulted function declaration is deleted

Is there a diagnostic flag or tool that can warn me if I have an explicitly defaulted function declaration that the compiler deletes?


Details

For instance, I had

class NotMoveA
{
public:
  explicit NotMoveA(Foo f) = default;
  ~NotMoveA() = default;
  NotMoveA(const NotMoveA &) = delete;
  NotMoveA(NotMoveA &&other) = default;
  NotMoveA &operator=(const NotMoveA &) = delete;
  //will B deleted w/o warning:
  NotMoveA &operator=(NotMoveA &&other) = default; 
  // ...
private:
  const std::string badDataMemberDisallowingMoveAssignment;
  // ...
}

and used NotMoveA in a std::vector. Since NotMoveA is not MoveAssignable, I got some errors whose cause took me quite a while to figure out. A warning directly at the cause, i.e. at the deleted = default function, would have helped.

Aucun commentaire:

Enregistrer un commentaire