[PATCH] D75053: [clangd] Disable ExtractVariable for C

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 25 03:12:20 PST 2020


kadircet updated this revision to Diff 246406.
kadircet marked an inline comment as done.
kadircet added a comment.

- Update comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75053

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -230,6 +230,14 @@
   )cpp";
   EXPECT_AVAILABLE(AvailableCases);
 
+  ExtraArgs = {"-xc"};
+  const char *AvailableButC = R"cpp(
+    void foo() {
+      int x = [[1]];
+    })cpp";
+  EXPECT_UNAVAILABLE(AvailableButC);
+  ExtraArgs = {};
+
   const char *NoCrashCases = R"cpp(
     // error-ok: broken code, but shouldn't crash
     template<typename T, typename ...Args>
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -450,6 +450,10 @@
   if (Inputs.SelectionBegin == Inputs.SelectionEnd)
     return false;
   const ASTContext &Ctx = Inputs.AST->getASTContext();
+  // FIXME: Enable non-C++ cases once we start spelling types explicitly instead
+  // of making use of auto.
+  if (!Ctx.getLangOpts().CPlusPlus)
+    return false;
   const SourceManager &SM = Inputs.AST->getSourceManager();
   if (const SelectionTree::Node *N =
           computeExtractedExpr(Inputs.ASTSelection.commonAncestor()))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75053.246406.patch
Type: text/x-patch
Size: 1361 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200225/881923d4/attachment.bin>


More information about the cfe-commits mailing list