diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp +++ b/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())) diff --git a/clang-tools-extra/clangd/unittests/TweakTests.cpp b/clang-tools-extra/clangd/unittests/TweakTests.cpp --- a/clang-tools-extra/clangd/unittests/TweakTests.cpp +++ b/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