summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp3
-rw-r--r--clang-tools-extra/test/clang-tidy/modernize-use-auto-new.cpp5
2 files changed, 8 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
index a9405471d29..1469909a85c 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
@@ -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.
diff --git a/clang-tools-extra/test/clang-tidy/modernize-use-auto-new.cpp b/clang-tools-extra/test/clang-tidy/modernize-use-auto-new.cpp
index 6468b20820e..f934c0de275 100644
--- a/clang-tools-extra/test/clang-tidy/modernize-use-auto-new.cpp
+++ b/clang-tools-extra/test/clang-tidy/modernize-use-auto-new.cpp
@@ -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();
}
OpenPOWER on IntegriCloud