[clang-tools-extra] r246638 - Fix use-auto-check.

Angel Garcia Gomez via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 2 03:20:00 PDT 2015


Author: angelgarcia
Date: Wed Sep  2 05:20:00 2015
New Revision: 246638

URL: http://llvm.org/viewvc/llvm-project?rev=246638&view=rev
Log:
Fix use-auto-check.

Summary: 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.

Reviewers: alexfh

Subscribers: cfe-commits, klimek

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

Modified:
    clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-new.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp?rev=246638&r1=246637&r2=246638&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp Wed Sep  2 05:20:00 2015
@@ -298,7 +298,7 @@ void UseAutoCheck::replaceIterators(cons
 }
 
 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;

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-new.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-new.cpp?rev=246638&r1=246637&r2=246638&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-new.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-new.cpp Wed Sep  2 05:20:00 2015
@@ -37,6 +37,8 @@ void auto_new() {
   // 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];




More information about the cfe-commits mailing list