tidy - bugprone-copy-constructor-init — Extra Clang Tools 22.0.0git documentation (original) (raw)

Finds copy constructors where the constructor doesn’t call the copy constructor of the base class.

class Copyable { public: Copyable() = default; Copyable(const Copyable &) = default;

int memberToBeCopied = 0; };

class X2 : public Copyable { X2(const X2 &other) {} // Copyable(other) is missing };

Also finds copy constructors where the constructor of the base class don’t have parameter.

class X3 : public Copyable { X3(const X3 &other) : Copyable() {} // other is missing };

Failure to properly initialize base class sub-objects during copy construction can result in undefined behavior, crashes, data corruption, or other unexpected outcomes. The check ensures that the copy constructor of a derived class properly calls the copy constructor of the base class, helping to prevent bugs and improve code quality.

Limitations

The check also suggests a fix-its in some cases.