berenm added inline comments.

================
Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:545
@@ +544,3 @@
+  if (const auto *Loc = Result.Nodes.getNodeAs<TypeLoc>("typeLoc")) {
+    if (const auto &Ref = Loc->getAs<TagTypeLoc>()) {
+      addUsage(NamingCheckFailures, Ref.getDecl(), Loc->getSourceRange(),
----------------
alexfh wrote:
> The four cases are too similar. It should be possible to write the code much 
> shorter. This might work:
> 
>   if (isa<TagTypeLoc>(Loc) || isa<InjectedClassNameTypeLoc>(Loc) || ...)
>     addUsage(NamingCheckFailures, Loc->getType()->getDecl(),
>         Loc->getSourceRange(), Result.SourceManager);
> 
It doesn't look to work well with `TypeLoc`. This looks to be a convoluted 
class hierarchy (http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html) and 
getDecl() is only available on some derived `TypeLoc` classes.

I can change to something smaller, is that any better?
```
    NamedDecl *Decl = nullptr;
    if (const auto &Ref = Loc->getAs<TagTypeLoc>()) {
      Decl = Ref.getDecl();
    } else if (const auto &Ref = Loc->getAs<InjectedClassNameTypeLoc>()) {
      Decl = Ref.getDecl();
    } else if (const auto &Ref = Loc->getAs<UnresolvedUsingTypeLoc>()) {
      Decl = Ref.getDecl();
    } else if (const auto &Ref = Loc->getAs<TemplateTypeParmTypeLoc>()) {
      Decl = Ref.getDecl();
    }

    if (Decl) {
      addUsage(NamingCheckFailures, Decl, Loc->getSourceRange(),
               Result.SourceManager);
      return;
    }
```


http://reviews.llvm.org/D13081



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to