[PATCH] D13504: Prevent modernize-use-auto from emitting a warning when 'auto' was already being used.

Angel Garcia via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 7 02:47:14 PDT 2015


angelgarcia created this revision.
angelgarcia added reviewers: klimek, bkramer.
angelgarcia added subscribers: alexfh, cfe-commits.

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

http://reviews.llvm.org/D13504

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  test/clang-tidy/modernize-use-auto-new.cpp

Index: test/clang-tidy/modernize-use-auto-new.cpp
===================================================================
--- test/clang-tidy/modernize-use-auto-new.cpp
+++ test/clang-tidy/modernize-use-auto-new.cpp
@@ -95,4 +95,7 @@
     // 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();
 }
Index: clang-tidy/modernize/UseAutoCheck.cpp
===================================================================
--- clang-tidy/modernize/UseAutoCheck.cpp
+++ clang-tidy/modernize/UseAutoCheck.cpp
@@ -222,6 +222,8 @@
              has(varDecl()),
              unless(has(varDecl(anyOf(
                  unless(hasInitializer(ignoringParenImpCasts(cxxNewExpr()))),
+                 // Skip declarations that are already using auto.
+                 hasType(autoType()),
                  // FIXME: TypeLoc information is not reliable where CV
                  // qualifiers are concerned so these types can't be
                  // handled for now.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13504.36722.patch
Type: text/x-patch
Size: 1114 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151007/4b845634/attachment.bin>


More information about the cfe-commits mailing list