From 2c19d4cee302c1e61bd39870e45c74ac9d140d87 Mon Sep 17 00:00:00 2001 From: Angel Garcia Gomez Date: Fri, 6 Nov 2015 15:47:04 +0000 Subject: Allow the alias to be of a different type. Summary: Consider a declaration an alias even if it doesn't have the same unqualified type than the container element, as long as one can be converted to the other using only implicit casts. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D14442 llvm-svn: 252315 --- .../clang-tidy/modernize/LoopConvertUtils.cpp | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp') diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp index 97e2f7e..c50e923 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp @@ -342,21 +342,27 @@ static bool isAliasDecl(ASTContext *Context, const Decl *TheDecl, if (!VDecl->hasInit()) return false; - const Expr *Init = - digThroughConstructors(VDecl->getInit()->IgnoreParenImpCasts()); + bool OnlyCasts = true; + const Expr *Init = VDecl->getInit()->IgnoreParenImpCasts(); + if (Init && isa(Init)) { + Init = digThroughConstructors(Init); + OnlyCasts = false; + } if (!Init) return false; // Check that the declared type is the same as (or a reference to) the // container type. - QualType InitType = Init->getType(); - QualType DeclarationType = VDecl->getType(); - if (!DeclarationType.isNull() && DeclarationType->isReferenceType()) - DeclarationType = DeclarationType.getNonReferenceType(); - - if (InitType.isNull() || DeclarationType.isNull() || - !Context->hasSameUnqualifiedType(DeclarationType, InitType)) - return false; + if (!OnlyCasts) { + QualType InitType = Init->getType(); + QualType DeclarationType = VDecl->getType(); + if (!DeclarationType.isNull() && DeclarationType->isReferenceType()) + DeclarationType = DeclarationType.getNonReferenceType(); + + if (InitType.isNull() || DeclarationType.isNull() || + !Context->hasSameUnqualifiedType(DeclarationType, InitType)) + return false; + } switch (Init->getStmtClass()) { case Stmt::ArraySubscriptExprClass: { @@ -384,8 +390,8 @@ static bool isAliasDecl(ASTContext *Context, const Decl *TheDecl, const auto *MemCall = cast(Init); // This check is needed because getMethodDecl can return nullptr if the // callee is a member function pointer. - if (MemCall->getMethodDecl() && - MemCall->getMethodDecl()->getName() == "at") { + const auto *MDecl = MemCall->getMethodDecl(); + if (MDecl && !isa(MDecl) && MDecl->getName() == "at") { assert(MemCall->getNumArgs() == 1); return isIndexInSubscriptExpr(MemCall->getArg(0), IndexVar); } -- cgit v1.1