[PATCH] D75053: [clangd] Disable ExtractVariable for C
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 24 07:44:53 PST 2020
kadircet created this revision.
kadircet added a reviewer: usaxena95.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.
Currently extract variable doesn't spell the type explicitly and just
uses an `auto` instead, which is not available in C.
Repository:
rG LLVM Github Monorepo
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 C (and maybe objective-c) 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.246208.patch
Type: text/x-patch
Size: 1373 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200224/bc3cc0fc/attachment-0001.bin>
More information about the cfe-commits
mailing list