[PATCH] D42116: [clang-tidy] Adding Fuchsia checker for trailing returns

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 17 07:35:34 PST 2018


aaron.ballman added inline comments.


================
Comment at: clang-tidy/fuchsia/TrailingReturnCheck.cpp:23
+  const auto *F = cast<FunctionProtoType>(T);
+  return F->hasTrailingReturn();
+}
----------------
I'd rewrite this as: `return Node.getType()->castAs<FunctionProtoType>()->hasTrailingReturnType();`


================
Comment at: clang-tidy/fuchsia/TrailingReturnCheck.cpp:26-28
+AST_MATCHER(QualType, isDecltypeType) {
+  return isa<DecltypeType>(Node.getTypePtr());
+}
----------------
Can you use something like this instead?

`extern const internal::VariadicDynCastAllOfMatcher<Type, DecltypeType> decltypeType;`


================
Comment at: clang-tidy/fuchsia/TrailingReturnCheck.cpp:30
+
+void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) {
+  // Functions which have trailing returns are disallowed, except for those 
----------------
The matchers should only be registered for C++11 and higher. This also fixes a bug where the `hasTrailingReturn()` would assert if given a K&R C function.


================
Comment at: clang-tidy/fuchsia/TrailingReturnCheck.cpp:31
+void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) {
+  // Functions which have trailing returns are disallowed, except for those 
+  // using decltype specifiers and lambda with otherwise unutterable 
----------------
s/which/that


================
Comment at: clang-tidy/fuchsia/TrailingReturnCheck.cpp:45
+  if (const auto *D = Result.Nodes.getNodeAs<Decl>("decl"))
+    diag(D->getLocStart(), "trailing returns are disallowed");
+}
----------------
The "trailing returns" isn't worded like our other diagnostics. How about "a trailing return type is disallowed for this declaration" or something along those lines?


================
Comment at: clang-tidy/fuchsia/TrailingReturnCheck.h:19
+
+/// Functions which have trailing returns are disallowed, except for those 
+/// using decltype specifiers and lambda with otherwise unutterable 
----------------
s/which/that


================
Comment at: docs/ReleaseNotes.rst:70
+
+  Functions which have trailing returns are disallowed, except for those 
+  using decltype specifiers and lambda with otherwise unutterable 
----------------
s/which/that


================
Comment at: docs/clang-tidy/checks/fuchsia-trailing-return.rst:6
+
+Functions which have trailing returns are disallowed, except for those using 
+decltype specifiers and lambda with otherwise unutterable return types.
----------------
s/which/that


https://reviews.llvm.org/D42116





More information about the cfe-commits mailing list