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

Piotr Zegar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 22 14:53:20 PST 2023


PiotrZSL created this revision.
Herald added a subscriber: xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Correct example, and add information about limitations.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144594

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


Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/copy-constructor-init.rst
===================================================================
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/copy-constructor-init.rst
+++ 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 @@
     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,28 @@
 
 .. 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
     };
 
+
+Uninitialized or improperly initialized base class sub-objects during copy
+construction can cause undefined behavior, crashes, data corruption, or other
+unexpected behavior.
+
+In summary check detects cases where the copy constructor of a derived class
+doesn't properly call or initialize 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144594.499653.patch
Type: text/x-patch
Size: 1950 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230222/ddf3a720/attachment-0001.bin>


More information about the cfe-commits mailing list