[PATCH] D135404: [clang-tidy] Add a checker for converting into C++17 variable template type traits

Roy Jacobson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 2 09:48:49 PDT 2022


royjacobson added a comment.

In D135404#3899904 <https://reviews.llvm.org/D135404#3899904>, @njames93 wrote:

> I'd also suggest using the `IgnoreUnlessSpelledInSource` traversal kind here. Given that most of the time these will be instantiated we don't want to warn and emit a fix for each instantiation, Or you could just add `unless(isInTemplateInstantiation())` to your matcher.

I'm not sure what to do here... Until this is instantiated, I have only a DependentScopeDeclRefExpr that is not resolved yet. And it's important to have this check for dependent contexts because that's how it's usually used.



================
Comment at: clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp:86
+    auto CurrentText = tooling::fixit::getText(*MatchedDecl, *Result.Context);
+    if (replacement_regex.match(CurrentText))
+      IssuedDiag << FixItHint::CreateReplacement(
----------------
njames93 wrote:
> royjacobson wrote:
> > njames93 wrote:
> > > This fixit logic looks cumbersome, just replace the qualifier loc(::)to the declared with an `_v`. But only iff the qualified name loc is not a macro.
> > I think to do that I have to get the location of the template-id of the qualifier from the ClassTemplateSpecializationDecl, but I haven't really managed to do that. Or is there maybe a way to get the lexer tokens list of a source range or something like that?
> Take a look here https://godbolt.org/z/Wj5bjbqGh
> You'd want to create an insertion of `_v` at the start of the `<`
> `getQualifierLoc().getTypeLoc().getAs<clang::TemplateSpecializationTypeLoc>().getLAngleLoc()`
> Then a removal from the start of the `::` until the end of the whole expr
> `{getQualifierLoc().getEndLoc(), getEndLoc()}`
That's great debugging tool, thanks! :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135404/new/

https://reviews.llvm.org/D135404



More information about the cfe-commits mailing list