[cfe-dev] [clang-tidy] problem finding AST matcher for nested implicit const-cast
Artem Dergachev via cfe-dev
cfe-dev at lists.llvm.org
Fri May 10 11:08:18 PDT 2019
The original matcher looks pretty weird to me, as the last anyOf() case,
namely "hasDescendant(BeginCallMatcher)", already matches more than all
previous anyOf() cases.
On 5/7/19 1:06 PM, Torbjörn Klatt via cfe-dev wrote:
> Hi all,
>
> I'm trying to fix the clang-tidy bug 35082 [1] as a starter for getting into LLVM development and contribution.
>
> I think, I've tracked down the issue to
>
> clang-tidy/modernize/LoopConvertCheck.cpp:123ff: clang::tidy::modernize::makeIteratorLoopMatcher()
> ```
> DeclarationMatcher InitDeclMatcher =
> varDecl(hasInitializer(anyOf(ignoringParenImpCasts(BeginCallMatcher),
> materializeTemporaryExpr(
> ignoringParenImpCasts(BeginCallMatcher)),
> hasDescendant(BeginCallMatcher))))
> .bind(InitVarName);
> ```
> The definition of `InitDeclMatcher` seems to not match the AST tree
> ```
> |-ForStmt
> | |-DeclStmt
> | | `-VarDecl
> | | `-ExprWithCleanups
> | | `-ImplicitCastExpr
> | | `-CXXConstructExpr
> | | `-MaterializeTemporaryExpr
> | | `-ImplicitCastExpr
> | | `-CXXMemberCallExpr
> | | `-MemberExpr
> | | `-DeclRefExpr
> ```
> of
> ```
> std::vector<int> vec{1, 2, 3, 4, 5};
> for(std::vector<int>::const_iterator i = vec.begin(); i != vec.end(); ++i) { ... }
> ```
>
> In my naivety, I tried to include the following into the `anyOf`:
> ```
> exprWithCleanups(
> ignoringParenImpCasts(
> cxxConstructExpr(
> materializeTemporaryExpr(
> ignoringParenImpCasts(
> BeginCallMatcher))))),
> ```
> mimicking the specific AST tree. Without luck.
>
> I browsed through include/clang/ASTMatchers.h for better suited matchers, but couldn't find any.
>
> What important detail am I missing?
>
> Best
> Torbjörn
>
> [1]: https://bugs.llvm.org/show_bug.cgi?id=35082
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list