<div dir="ltr">I think you might be able to safely remove this `if else`, or at least limit it.<div><br></div><div>Consider the following:<div><br></div><div><font face="monospace, monospace">// this is your test case. it's legal, but currently ignored</font></div><div><font face="monospace, monospace">std::vector<int> v;</font></div><div><font face="monospace, monospace">for(std::vector<int>::const_iterator i = v.begin(); i != v.end(); ++i) {}</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">// these aren't illegal, and therefore never even considered by the checker -- they cause a compiler error</font></div><div><font face="monospace, monospace">for(std::vector<int>::iterator i = v.cbegin(); i != v.cend(); ++i) {}</font></div><div><font face="monospace, monospace">const std::vector<int> cv;</font></div><div><font face="monospace, monospace">for(std::vector<int>::iterator i = cv.begin(); i != cv.end(); ++i) {}</font></div><div><br></div><div><br></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 10, 2019 at 4:45 PM Don Hinton <<a href="mailto:hintonda@gmail.com">hintonda@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Hi Torbjörn:<div><br></div><div>This behavior appears to be intentional, though it would be friendly to emit a warning.  I believe this is the case your are hitting:</div><div><br></div><div><div>   794      } else if (!Context->hasSameType(CanonicalInitVarType,</div><div>   795                                       CanonicalBeginType)) {</div><div>   796        // Check for qualified types to avoid conversions from non-const to const</div><div>   797        // iterator types.</div><div>   798        return false;</div><div>   799      }</div></div><div><br></div><div>hth...</div><div>don</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 7, 2019 at 1:06 PM Torbjörn Klatt via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi all,<br>
<br>
I'm trying to fix the clang-tidy bug 35082 [1] as a starter for getting into LLVM development and contribution.<br>
<br>
I think, I've tracked down the issue to<br>
<br>
clang-tidy/modernize/LoopConvertCheck.cpp:123ff: clang::tidy::modernize::makeIteratorLoopMatcher()<br>
```<br>
  DeclarationMatcher InitDeclMatcher =<br>
      varDecl(hasInitializer(anyOf(ignoringParenImpCasts(BeginCallMatcher),<br>
                                   materializeTemporaryExpr(<br>
                                       ignoringParenImpCasts(BeginCallMatcher)),<br>
                                   hasDescendant(BeginCallMatcher))))<br>
          .bind(InitVarName);<br>
```<br>
The definition of `InitDeclMatcher` seems to not match  the AST tree<br>
```<br>
  |-ForStmt<br>
  | |-DeclStmt<br>
  | | `-VarDecl<br>
  | |   `-ExprWithCleanups<br>
  | |     `-ImplicitCastExpr<br>
  | |       `-CXXConstructExpr<br>
  | |         `-MaterializeTemporaryExpr<br>
  | |           `-ImplicitCastExpr<br>
  | |             `-CXXMemberCallExpr<br>
  | |               `-MemberExpr <br>
  | |                 `-DeclRefExpr<br>
```<br>
of<br>
```<br>
std::vector<int> vec{1, 2, 3, 4, 5};<br>
for(std::vector<int>::const_iterator i = vec.begin(); i != vec.end(); ++i) { ... }<br>
```<br>
<br>
In my naivety, I tried to include the following into the `anyOf`:<br>
```<br>
                                   exprWithCleanups(<br>
                                       ignoringParenImpCasts(<br>
                                           cxxConstructExpr(<br>
                                               materializeTemporaryExpr(<br>
                                                   ignoringParenImpCasts(<br>
                                                       BeginCallMatcher))))),<br>
```<br>
mimicking the specific AST tree. Without luck.<br>
<br>
I browsed through include/clang/ASTMatchers.h for better suited matchers, but couldn't find any.<br>
<br>
What important detail am I missing?<br>
<br>
Best<br>
Torbjörn<br>
<br>
[1]: <a href="https://bugs.llvm.org/show_bug.cgi?id=35082" rel="noreferrer" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=35082</a><br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>
</blockquote></div>