Skip to content

Remove old code declaring unimplemented copy constructors/operators

Years ago, privately declaring but not implementing these two functions was the accepted way to suppress copying in a class. However, QObject is already noncopyable, making its subclasses noncopyable anyway. Therefore this code is unnecessary, as can be verified on any of these classes T with:

  static_assert(!std::is_copy_constructible_v<T>);
  static_assert(!std::is_copy_assignable_v<T>);

(Some have argued in the past that explicitly suppressing these, while unnecessary, produced more helpful error messages, when callers try to copy a noncopyable QObject subclass: https://stackoverflow.com/questions/19854371/repeating-q-disable-copy-in-qobject-derived-classes. However, modern compilers produce quite clear error message when trying to copy an object that inherits from a noncopyable object like QObject.)

Alternatives: Instead of deleting these, they could be updated to use = delete or Q_DISABLE_COPY. Really only those in pqWidgetEventTranslator.h caused link errors for me, because they were declared protected rather than private. But as these unimplemented declarations are all unnecessary, deleting them entirely seems the best solution.

Merge request reports

Loading