<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2016-09-21 12:48 GMT-07:00 Matthias Vallentin via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I'm in the process of writing a clang-tidy check that concerns the<br>
position of the "const" keyword. The check should either enforce "T<br>
const" or "const T", based on a flag. Naturally, this should extend to<br>
all sorts of variations and qualifiers, e.g., X<const T&, Y const*><br>
const&.<br>
<br>
My approach is to first find the right AST matcher expression to flag<br>
style violations, and then use the lexer (getLocStart/End) to correct<br>
them [1]. Does that sound reasonable? There's also<br>
Qualifiers::removeConst and Qualifiers::addConst, but I'm not sure how<br>
it affects the position of const.<br>
<br></blockquote><div>Writing simple matcher and then do lexer magic seems the best idea.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I have trouble with finding all const-qualified types. I looked at<br>
misc-misplaced-const for inspiration, which contains this matcher:<br>
<br>
    valueDecl(hasType(<wbr>isConstQualified()))<br>
<br>
Why doesn't this yield a match? My test code has this form:<br>
<br>
    template <class T><br>
    struct type {};<br>
<br>
    template <class T><br>
    void f(const type<const double>&, const T&) {<br>
    }<br>
<br></blockquote><div>Not really sure, but I would guess that this matcher might work only for template instantiations (if you will use this function somewhere)[ </div><div>I guess the misc-misplaced-const might have a bug.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
    using alias = const int&;<br></blockquote><div>I guess this doesn't match because it is alias declaration. Use </div><table style="font-family:"lucida grande","lucida sans unicode",arial,verdana,helvetica,sans-serif"><tbody><tr style="vertical-align:top"><td class="gmail-name" style="padding:0.33em"><a name="typedefNameDecl0Anchor"><br class="gmail-Apple-interchange-newline">typedefNameDecl</a></td></tr></tbody></table><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
I've tested this expression with clang-query (master branch). Any help<br>
that steers me in the right direction would be much appreciated.<br>
<br>
    Matthias<br></blockquote><div>Piotr</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br></div></div>