[PATCH] D96247: [clangd] Fix false positive in local rename collision detetction

Kirill Bobyrev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 8 00:53:54 PST 2021


kbobyrev updated this revision to Diff 322045.
kbobyrev added a comment.

Fix comment formatting in the test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96247/new/

https://reviews.llvm.org/D96247

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1083,12 +1083,23 @@
        "conflict", !HeaderFile, nullptr, "Conflict"},
 
       {R"cpp(
+        void func(int Var);
+
         void func(int V^ar) {
           bool Conflict;
         }
       )cpp",
        "conflict", !HeaderFile, nullptr, "Conflict"},
 
+      {R"cpp(// No conflict: only forward declaration's argument is renamed.
+        void func(int [[V^ar]]);
+
+        void func(int Var) {
+          bool Conflict;
+        }
+      )cpp",
+       nullptr, !HeaderFile, nullptr, "Conflict"},
+
       {R"cpp(
         void func(int V^ar, int Conflict) {
         }
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -421,6 +421,11 @@
     for (const auto *Parameter : EnclosingFunction->parameters())
       if (Parameter != &RenamedDecl && Parameter->getName() == NewName)
         return Parameter;
+    // FIXME: We don't modify all references to function parameters when
+    // renaming from forward declaration now, so using a name colliding with
+    // something in the definition's body is a valid transformation.
+    if (!EnclosingFunction->isThisDeclarationADefinition())
+      return nullptr;
     return CheckCompoundStmt(EnclosingFunction->getBody(), NewName);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96247.322045.patch
Type: text/x-patch
Size: 1611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210208/55f6d3d4/attachment-0001.bin>


More information about the cfe-commits mailing list