Skip to content

Commit

Permalink
Prevent modernize-use-auto from emitting a warning when 'auto' was al…
Browse files Browse the repository at this point in the history
…ready 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
  • Loading branch information
angargo committed Oct 14, 2015
1 parent baf573e commit 2df3648
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions clang-tools-extra/test/clang-tidy/modernize-use-auto-new.cpp
Expand Up @@ -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();
}

0 comments on commit 2df3648

Please sign in to comment.