Prevent modernize-use-auto from emitting a warning when 'auto' was already being used.

Summary: This fixes https://llvm.org/bugs/show_bug.cgi?id=25082 .

Reviewers: bkramer, klimek

Subscribers: cfe-commits, alexfh

Differential Revision: http://reviews.llvm.org/D13504

llvm-svn: 250284
This commit is contained in:
Angel Garcia Gomez 2015-10-14 09:29:55 +00:00
parent baf573eb4c
commit 2df36481b6
2 changed files with 8 additions and 0 deletions

View File

@ -222,6 +222,9 @@ StatementMatcher makeDeclWithNewMatcher() {
has(varDecl()),
unless(has(varDecl(anyOf(
unless(hasInitializer(ignoringParenImpCasts(cxxNewExpr()))),
// Skip declarations that are already using auto.
anyOf(hasType(autoType()),
hasType(pointerType(pointee(autoType())))),
// FIXME: TypeLoc information is not reliable where CV
// qualifiers are concerned so these types can't be
// handled for now.

View File

@ -95,4 +95,9 @@ void auto_new() {
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use auto when initializing with new
// CHECK-FIXES: auto g = new int*, h = new int_p;
}
// Don't warn when 'auto' is already being used.
auto aut = new MyType();
auto *paut = new MyType();
const auto *pcaut = new MyType();
}