hokein created this revision.
hokein added a reviewer: aaron.ballman.
Herald added a subscriber: xazax.hun.

The fix for `auto` new expression is illegal.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54832

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  test/clang-tidy/modernize-make-unique.cpp


Index: test/clang-tidy/modernize-make-unique.cpp
===================================================================
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -282,6 +282,11 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
   // CHECK-FIXES: PE1 = std::make_unique<E>();
 
+  // No fixes for `auto` new expression.
+  PE1.reset(new auto(E()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
+  // CHECK-FIXES: PE1.reset(new auto(E()));
+
   
//============================================================================
   //  NOTE: For initlializer-list constructors, the check only gives warnings,
   //  and no fixes are generated.
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===================================================================
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -252,6 +252,9 @@
 bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
                                    const CXXNewExpr *New, SourceManager &SM,
                                    ASTContext *Ctx) {
+  // Skip when this is a new-expression with `auto`, e.g. "new auto(1)"."
+  if (New->getType()->getPointeeType()->getContainedAutoType())
+    return false;
   auto SkipParensParents = [&](const Expr *E) {
     for (const Expr *OldE = nullptr; E != OldE;) {
       OldE = E;


Index: test/clang-tidy/modernize-make-unique.cpp
===================================================================
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -282,6 +282,11 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
   // CHECK-FIXES: PE1 = std::make_unique<E>();
 
+  // No fixes for `auto` new expression.
+  PE1.reset(new auto(E()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
+  // CHECK-FIXES: PE1.reset(new auto(E()));
+
   //============================================================================
   //  NOTE: For initlializer-list constructors, the check only gives warnings,
   //  and no fixes are generated.
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===================================================================
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -252,6 +252,9 @@
 bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
                                    const CXXNewExpr *New, SourceManager &SM,
                                    ASTContext *Ctx) {
+  // Skip when this is a new-expression with `auto`, e.g. "new auto(1)"."
+  if (New->getType()->getPointeeType()->getContainedAutoType())
+    return false;
   auto SkipParensParents = [&](const Expr *E) {
     for (const Expr *OldE = nullptr; E != OldE;) {
       OldE = E;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to