From 1d66e366e96d9622bfdbc9a78383033e89a808b4 Mon Sep 17 00:00:00 2001 From: "Ariel J. Bernal" Date: Mon, 27 May 2013 14:30:23 +0000 Subject: Fix UseAuto replacing declaration lists with new expressions UseAuto used to replace declarion lists with new expressons where some variable were not initialized with new. This fix checks that every DeclStmt has a VarDecl with an initializer and it also ensures that all declarations have the same type. Added tests for multiple declarations and for typedefs. llvm-svn: 182736 --- .../cpp11-migrate/UseAuto/UseAutoMatchers.cpp | 48 +++++++++++----------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'clang-tools-extra/cpp11-migrate/UseAuto/UseAutoMatchers.cpp') diff --git a/clang-tools-extra/cpp11-migrate/UseAuto/UseAutoMatchers.cpp b/clang-tools-extra/cpp11-migrate/UseAuto/UseAutoMatchers.cpp index 246378ac9aa..60d29b24584 100644 --- a/clang-tools-extra/cpp11-migrate/UseAuto/UseAutoMatchers.cpp +++ b/clang-tools-extra/cpp11-migrate/UseAuto/UseAutoMatchers.cpp @@ -258,29 +258,29 @@ StatementMatcher makeIteratorDeclMatcher() { ).bind(IteratorDeclStmtId); } -DeclarationMatcher makeDeclWithNewMatcher() { - return varDecl( - hasInitializer( - ignoringParenImpCasts( - newExpr().bind(NewExprId) - ) - ), - - // FIXME: TypeLoc information is not reliable where CV qualifiers are - // concerned so these types can't be handled for now. - unless(hasType(pointerType(pointee(hasLocalQualifiers())))), +StatementMatcher makeDeclWithNewMatcher() { + return declStmt( + has(varDecl()), + unless(has(varDecl( + anyOf( + unless(hasInitializer( + ignoringParenImpCasts(newExpr()) + )), + // FIXME: TypeLoc information is not reliable where CV qualifiers are + // concerned so these types can't be handled for now. + hasType(pointerType(pointee(hasCanonicalType(hasLocalQualifiers())))), - // FIXME: Handle function pointers. For now we ignore them because - // the replacement replaces the entire type specifier source range - // which includes the identifier. - unless( - hasType( - pointsTo( - pointsTo( - parenType(innerType(functionType())) - ) - ) - ) - ) - ).bind(DeclWithNewId); + // FIXME: Handle function pointers. For now we ignore them because + // the replacement replaces the entire type specifier source range + // which includes the identifier. + hasType( + pointsTo( + pointsTo( + parenType(innerType(functionType())) + ) + ) + ) + ) + ))) + ).bind(DeclWithNewId); } -- cgit v1.2.3