diff --git a/clang/lib/Tooling/Syntax/BuildTree.cpp b/clang/lib/Tooling/Syntax/BuildTree.cpp --- a/clang/lib/Tooling/Syntax/BuildTree.cpp +++ b/clang/lib/Tooling/Syntax/BuildTree.cpp @@ -378,11 +378,9 @@ /// Returns true if \p D is the last declarator in a chain and is thus /// reponsible for creating SimpleDeclaration for the whole chain. - template - bool isResponsibleForCreatingDeclaration(const T *D) const { - static_assert((std::is_base_of::value || - std::is_base_of::value), - "only DeclaratorDecl and TypedefNameDecl are supported."); + bool isResponsibleForCreatingDeclaration(const Decl *D) const { + assert((isa(D)) && + "only DeclaratorDecl and TypedefNameDecl are supported."); const Decl *Next = D->getNextDeclInContext(); @@ -390,15 +388,14 @@ if (Next == nullptr) { return true; } - const auto *NextT = dyn_cast(Next); // Next sibling is not the same type, this one is responsible. - if (NextT == nullptr) { + if (D->getKind() != Next->getKind()) { return true; } // Next sibling doesn't begin at the same loc, it must be a different // declaration, so this declarator is responsible. - if (NextT->getBeginLoc() != D->getBeginLoc()) { + if (Next->getBeginLoc() != D->getBeginLoc()) { return true; } @@ -1405,10 +1402,9 @@ } private: - template SourceLocation getQualifiedNameStart(T *D) { - static_assert((std::is_base_of::value || - std::is_base_of::value), - "only DeclaratorDecl and TypedefNameDecl are supported."); + SourceLocation getQualifiedNameStart(NamedDecl *D) { + assert((isa(D)) && + "only DeclaratorDecl and TypedefNameDecl are supported."); auto DN = D->getDeclName(); bool IsAnonymous = DN.isIdentifier() && !DN.getAsIdentifierInfo(); @@ -1438,10 +1434,9 @@ /// Folds SimpleDeclarator node (if present) and in case this is the last /// declarator in the chain it also folds SimpleDeclaration node. template bool processDeclaratorAndDeclaration(T *D) { - SourceRange Initializer = getInitializerRange(D); - auto Range = getDeclaratorRange(Builder.sourceManager(), - D->getTypeSourceInfo()->getTypeLoc(), - getQualifiedNameStart(D), Initializer); + auto Range = getDeclaratorRange( + Builder.sourceManager(), D->getTypeSourceInfo()->getTypeLoc(), + getQualifiedNameStart(D), getInitializerRange(D)); // There doesn't have to be a declarator (e.g. `void foo(int)` only has // declaration, but no declarator).