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;
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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits