[PATCH] misc-uninitialized-field

Alexander Kornienko alexfh at google.com
Sun Jun 21 01:44:40 PDT 2015


================
Comment at: clang-tidy/misc/UninitializedFieldCheck.cpp:14
@@ +13,3 @@
+#include <unordered_set>
+#include <sstream>
+#include <iterator>
----------------
#includes should be sorted (e.g. using the llvm-include-order check, `clang-tidy -fix` should do the trick).

================
Comment at: clang-tidy/misc/UninitializedFieldCheck.cpp:24
@@ +23,3 @@
+
+static bool fieldRequiresInit(const clang::FieldDecl *f) {
+  if (f->getType()->isPointerType()) 
----------------
Variable names should start with a capital letter.

================
Comment at: clang-tidy/misc/UninitializedFieldCheck.cpp:25
@@ +24,3 @@
+static bool fieldRequiresInit(const clang::FieldDecl *f) {
+  if (f->getType()->isPointerType()) 
+    return true;
----------------
  return f->getType()->isPointerType() || f->getType()->isBuiltinType();

================
Comment at: clang-tidy/misc/UninitializedFieldCheck.cpp:41
@@ +40,3 @@
+  if (const auto *Ctor = Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor")) {
+    // TODO: Add constructor if the compiler-generated one is not sufficient
+    if (!Ctor->isUserProvided()) 
----------------
nit: Please add trailing period

================
Comment at: clang-tidy/misc/UninitializedFieldCheck.cpp:56
@@ +55,3 @@
+    
+    for (clang::CXXCtorInitializer *Init : Ctor->inits()) {
+      const FieldDecl *MemberField = Init->getMember();
----------------
What about fields initialized in the constructor body?

================
Comment at: clang-tidy/misc/UninitializedFieldCheck.cpp:70
@@ +69,3 @@
+
+    std::stringstream ss;
+    for (const auto MemberField : MemberFields) 
----------------
In LLVM code, `llvm::raw_string_ostream` or `llvm::raw_svector_ostream` are used instead of `std::stringstream`.

================
Comment at: clang-tidy/misc/UninitializedFieldCheck.cpp:82
@@ +81,3 @@
+    // Do we need a ':' or a ',' at the beginning of our new initializer list?
+    auto it_WrittenInitializer =
+        std::find_if(Ctor->inits().begin(), Ctor->inits().end(),
----------------
http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly

================
Comment at: clang-tidy/misc/UninitializedFieldCheck.cpp:94
@@ +93,3 @@
+    diag(Ctor->getLocStart(),
+         "Constructor '%0' needs to initialize all built-in or pointer fields.")
+        << Ctor->getNameAsString()
----------------
We use the same style for messages, as Clang: first letter is lower-case, no trailing period.

http://reviews.llvm.org/D10553

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list