[PATCH] [clang-tidy] Add a checker for code that looks like a delegate constructors but doesn't delegate.

Alexander Kornienko alexfh at google.com
Tue Jul 29 07:45:32 PDT 2014


================
Comment at: clang-tidy/misc/CMakeLists.txt:9
@@ -8,2 +8,3 @@
   SwappedArgumentsCheck.cpp
+  UndelegatedConstructor.cpp
   UnusedRAII.cpp
----------------
I'd add "Check" to the class name for consistency.

================
Comment at: clang-tidy/misc/UndelegatedConstructor.cpp:63
@@ +62,3 @@
+                  .bind("construct"))),
+          unless(hasAncestor(decl(
+              anyOf(recordDecl(ast_matchers::isTemplateInstantiation()),
----------------
Please add a test with template instantiations. It's useful to know that the matcher doesn't crash on them ;)

================
Comment at: clang-tidy/misc/UndelegatedConstructor.cpp:72
@@ +71,3 @@
+  diag(E->getLocStart(),
+       "calling a different constructor in a constructor does not chain them");
+}
----------------
The message could be a bit clearer of what actually happens here. Maybe something along the lines of: "Did you intend to call a delegated constructor? A temporary object is created here instead"

================
Comment at: test/clang-tidy/misc-undelegated-constructor.cpp:1
@@ +1,2 @@
+// RUN: clang-tidy -checks='-*,misc-undelegated-constructor' %s -- -std=c++11 2>&1 | FileCheck %s
+
----------------
Please add -implicit-check-not='{{warning:|error:}}'.

http://reviews.llvm.org/D4667






More information about the cfe-commits mailing list