Author: Piotr Zegar
Date: 2023-02-26T08:58:04Z
New Revision: e168964ce1fb3747746afcc46817eeb6706df6ed

URL: 
https://github.com/llvm/llvm-project/commit/e168964ce1fb3747746afcc46817eeb6706df6ed
DIFF: 
https://github.com/llvm/llvm-project/commit/e168964ce1fb3747746afcc46817eeb6706df6ed.diff

LOG: [clang-tidy] Fix bugprone-copy-constructor-init documentation

Correct example, and add information about limitations.

Fixes: https://github.com/llvm/llvm-project/issues/55572

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D144594

Added: 
    

Modified: 
    clang-tools-extra/docs/clang-tidy/checks/bugprone/copy-constructor-init.rst

Removed: 
    


################################################################################
diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/copy-constructor-init.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/copy-constructor-init.rst
index a2b39bc4ff30a..cc3291b9b908e 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/copy-constructor-init.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/copy-constructor-init.rst
@@ -3,8 +3,8 @@
 bugprone-copy-constructor-init
 ==============================
 
-Finds copy constructors where the constructor doesn't call
-the copy constructor of the base class.
+Finds copy constructors where the constructor doesn't call the copy constructor
+of the base class.
 
 .. code-block:: c++
 
@@ -12,7 +12,10 @@ the copy constructor of the base class.
     public:
       Copyable() = default;
       Copyable(const Copyable &) = default;
+
+      int memberToBeCopied = 0;
     };
+
     class X2 : public Copyable {
       X2(const X2 &other) {} // Copyable(other) is missing
     };
@@ -22,8 +25,25 @@ the base class don't have parameter.
 
 .. code-block:: c++
 
-    class X4 : public Copyable {
-      X4(const X4 &other) : Copyable() {} // other is missing
+    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:
+
+* It won't generate warnings for empty classes, as there are no class members
+  (including base class sub-objects) to worry about.
+
+* It won't generate warnings for base classes that have copy constructor
+  private or deleted.
+
+* It won't generate warnings for base classes that are initialized using other
+  non-default constructor, as this could be intentional.
+
 The check also suggests a fix-its in some cases.


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to