[PATCH] D44346: [clang-tidy] Add Fuchsia checker for temporary objects

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 12 13:04:14 PDT 2018


aaron.ballman added inline comments.


================
Comment at: clang-tidy/fuchsia/FuchsiaTidyModule.cpp:44
+    CheckFactories.registerCheck<ZxTemporaryObjectsCheck>(
+        "fuchsia-zx-temporary-objects");
   }
----------------
Do we want a zircon module instead? I'm wondering about people who enable modules by doing `fuchsia-*` and whether or not they would expect this check (and others for zircon) to be enabled.


================
Comment at: clang-tidy/fuchsia/ZxTemporaryObjectsCheck.cpp:46
+void ZxTemporaryObjectsCheck::check(const MatchFinder::MatchResult &Result) {
+  if (const auto *D = Result.Nodes.getNodeAs<CXXConstructExpr>("temps")) {
+    diag(D->getLocation(), "misuse of temporary object");
----------------
Elide braces.


================
Comment at: clang-tidy/fuchsia/ZxTemporaryObjectsCheck.cpp:47
+  if (const auto *D = Result.Nodes.getNodeAs<CXXConstructExpr>("temps")) {
+    diag(D->getLocation(), "misuse of temporary object");
+  }
----------------
I think this could be stated more clearly as "creating a temporary object of type %0 is prohibited" and pass in the temporary type. That will also help the user to identify what type is problematic in something like: `f(good_temp{}, bad_temp{}, good_temp{});`. I'm not tied to printing the type, but "misuse" suggests there's a better way to use the temporary object, which I don't think is a correct interpretation.


================
Comment at: clang-tidy/fuchsia/ZxTemporaryObjectsCheck.h:20
+
+/// Constructing of specific temporary objects in the Zircon kernel is
+/// discouraged. Takes the list of such discouraged temporary objects as a
----------------
Construction instead of constructing?


https://reviews.llvm.org/D44346





More information about the cfe-commits mailing list