[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

Piotr Padlewski via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 13 08:15:12 PST 2016


Prazek added a comment.

In https://reviews.llvm.org/D27166#617696, @malcolm.parsons wrote:

> In https://reviews.llvm.org/D27166#617621, @Prazek wrote:.
>
> > Does it work for cases like?
>
>
> Yes; `replaceExpr()` checks that the variable has the same unqualified type as the initializer and the same canonical type as other variables in the declaration.


Can you add this small test?



================
Comment at: clang-tidy/modernize/UseAutoCheck.cpp:173-177
+/// Matches the type that was substituted for the template parameter.
+AST_MATCHER_P(SubstTemplateTypeParmType, hasReplacementType,
+              ast_matchers::internal::Matcher<QualType>, InnerMatcher) {
+  return InnerMatcher.matches(Node.getReplacementType(), Finder, Builder);
+}
----------------
alexfh wrote:
> Ideally, this should go to ASTMatchers.h (with a proper test and documentation).
I agree 


================
Comment at: clang-tidy/modernize/UseAutoCheck.cpp:256-264
+  return declStmt(
+             unless(has(varDecl(unless(hasInitializer(ignoringImplicit(callExpr(
+                 anyOf(has(memberExpr(hasExplicitTemplateArgs())),
+                       has(ignoringImpCasts(
+                           declRefExpr(hasExplicitTemplateArgs())))),
+                 callee(functionDecl(
+                     hasTemplateArgument(0,
----------------
Can you split this matcher into 3 matchers? It is so large that even clang-format doesn't help with it.
And also because of that I can't come up with good auto variables to use here, because I don't know where the parens ends.


================
Comment at: docs/clang-tidy/checks/modernize-use-auto.rst:165
+that behave as casts, such as ``llvm::dyn_cast``, ``boost::lexical_cast`` and
+``gsl::narrow_cast``.
 
----------------
I would add to that what functions are considered (functions returning type chosen as first template parameter or something similar). Now someone could think that there is hardcoded list somewhere.


https://reviews.llvm.org/D27166





More information about the cfe-commits mailing list