[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
Wed Dec 14 07:35:04 PST 2016


Prazek added a comment.

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

> In https://reviews.llvm.org/D27166#622103, @Prazek wrote:
>
> > There is still one more problem:
> >
> >   /home/prazek/llvm/lib/Analysis/ScalarEvolution.cpp:2442:11: warning: use auto when initializing with a template cast to avoid duplicating the type name [modernize-use-auto]
> >     const auto **O = SCEVAllocator.Allocate<const SCEV *>(Ops.size());
> >           ^
> >           auto 
>
>
> Any suggestions for rewriting this matcher?
>
>   // Skip declarations that are already using auto.
>   unless(has(varDecl(anyOf(hasType(autoType()),
>                            hasType(pointerType(pointee(autoType()))),
>                            hasType(referenceType(pointee(autoType())))))))
>   
>
> > There is also problem with function pointers
> > 
> >   /home/prazek/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp:520:9: warning: use auto when initializing with a cast to avoid duplicating the type name [modernize-use-auto]
> >         int (*PF)(int, char **, const char **) =
> >         ^
> >         auto                                                                                                                                                                                                                             
>
> The warning is correct, but the fixit is wrong.
>  Suppress fixit for function pointers?


Yep, it is not worth fixing it. Have you add test cases to the cases that we discussed?



================
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);
+}
----------------
malcolm.parsons wrote:
> Prazek wrote:
> > alexfh wrote:
> > > Ideally, this should go to ASTMatchers.h (with a proper test and documentation).
> > I agree 
> @Prazek Are you talking about `hasReplacementType` or `hasExplicitTemplateArgs`?
It is good now.


https://reviews.llvm.org/D27166





More information about the cfe-commits mailing list