[clang-tools-extra] [clang-tidy] The first PR our of many PRs for the "Initialized Class Members" check. (PR #65189)

Piotr Zegar via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 8 12:25:18 PDT 2023


================
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - google-cpp-init-class-members
+
+google-cpp-init-class-members
+=============================
+
+Checks that class members are initialized in constructors (implicitly or
+explicitly). Reports constructors or classes where class members are not
+initialized. The goal of this checker is to eliminate UUM (Use of
+Uninitialized Memory) bugs caused by uninitialized class members.
+
+This checker is different from ProTypeMemberInitCheck in that this checker
+attempts to eliminate UUMs as a bug class, at the expense of false
+positives.
----------------
PiotrZSL wrote:

First example is fine, but for that exist check should be just extended.
Second example is not so fine, simply because this is POD, and by adding initialization you change this, and this may impact usage of such class, like zeroed using memset, used in union. For me if you want to force initialization for such classes, this should be separated check or option in exist one, maybe distinguish based on keyword struct vs class.
Last issue is already detected by cppcoreguidelines-pro-type-member-init.

https://github.com/llvm/llvm-project/pull/65189


More information about the cfe-commits mailing list