[clang-tools-extra] [clangd] Extract to function: Do not reject unconditionally in C files (PR #228465)

Aleksandr Platonov via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 6 23:58:17 PDT 2026


================
@@ -1112,6 +1297,12 @@ llvm::Expected<NewFunction> getExtractedFunction(ExtractionZone &ExtZone,
   ExtractedFunc.DefinitionQualifier = ExtZone.EnclosingFunction->getQualifier();
   ExtractedFunc.Constexpr = ExtZone.EnclosingFunction->getConstexprKind();
 
+  // A free function declared `static` has internal linkage: an extracted
+  // sibling should keep that, or it'd default to external linkage instead.
+  // For a method, this gets overridden just below by the more precise
+  // (and differently-meaning) CXXMethodDecl::isStatic().
+  ExtractedFunc.Static =
+      ExtZone.EnclosingFunction->getStorageClass() == SC_Static;
----------------
ArcsinX wrote:

We need to check canonical declaration here, but not current declaration to support forward declaration of static function.
E.g.
```cpp
static void f();

void f() // no static here, but f is a static function
{
.....// code to extract here
}
```

https://github.com/llvm/llvm-project/pull/228465


More information about the cfe-commits mailing list