1 .. title:: clang-tidy - bugprone-copy-constructor-init
3 bugprone-copy-constructor-init
4 ==============================
6 Finds copy constructors where the constructor doesn't call the copy constructor
14 Copyable(const Copyable &) = default;
16 int memberToBeCopied = 0;
19 class X2 : public Copyable {
20 X2(const X2 &other) {} // Copyable(other) is missing
23 Also finds copy constructors where the constructor of
24 the base class don't have parameter.
28 class X3 : public Copyable {
29 X3(const X3 &other) : Copyable() {} // other is missing
32 Failure to properly initialize base class sub-objects during copy construction
33 can result in undefined behavior, crashes, data corruption, or other unexpected
34 outcomes. The check ensures that the copy constructor of a derived class
35 properly calls the copy constructor of the base class, helping to prevent bugs
36 and improve code quality.
40 * It won't generate warnings for empty classes, as there are no class members
41 (including base class sub-objects) to worry about.
43 * It won't generate warnings for base classes that have copy constructor
46 * It won't generate warnings for base classes that are initialized using other
47 non-default constructor, as this could be intentional.
49 The check also suggests a fix-its in some cases.