[PATCH] D12551: Fix use-auto-check.

Angel Garcia via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 2 03:07:39 PDT 2015


angelgarcia created this revision.
angelgarcia added a reviewer: alexfh.
angelgarcia added subscribers: klimek, cfe-commits.

Fix a bug where use-auto check would crash when the definition of a type is in the same statement than its instantiation with new.

http://reviews.llvm.org/D12551

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
@@ -37,6 +37,8 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with new
   // CHECK-FIXES: auto  volatile vol = new MyType();
 
+  struct SType {} *stype = new SType;
+
   int (**func)(int, int) = new (int(*[5])(int,int));
 
   int *array = new int[5];
Index: clang-tidy/modernize/UseAutoCheck.cpp
===================================================================
--- clang-tidy/modernize/UseAutoCheck.cpp
+++ clang-tidy/modernize/UseAutoCheck.cpp
@@ -298,7 +298,7 @@
 }
 
 void UseAutoCheck::replaceNew(const DeclStmt *D, ASTContext *Context) {
-  const auto *FirstDecl = cast<VarDecl>(*D->decl_begin());
+  const auto *FirstDecl = dyn_cast<VarDecl>(*D->decl_begin());
   // Ensure that there is at least one VarDecl within the DeclStmt.
   if (!FirstDecl)
     return;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12551.33792.patch
Type: text/x-patch
Size: 1014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150902/b057a247/attachment.bin>


More information about the cfe-commits mailing list