[clang-tools-extra] [clangd] Allow "move function body out-of-line" in non-header files (PR #69704)

kadir çetinkaya via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 21 01:49:47 PST 2023


================
@@ -435,14 +407,17 @@ class DefineOutline : public Tweak {
       if (MD->getParent()->isTemplated())
         return false;
 
-      // The refactoring is meaningless for unnamed classes and definitions
-      // within unnamed namespaces.
+      // The refactoring is meaningless for unnamed classes.
       for (const DeclContext *DC = MD->getParent(); DC; DC = DC->getParent()) {
         if (auto *ND = llvm::dyn_cast<NamedDecl>(DC)) {
-          if (ND->getDeclName().isEmpty())
+          if (ND->getDeclName().isEmpty() &&
+              (!SameFile || !llvm::dyn_cast<NamespaceDecl>(ND)))
             return false;
         }
       }
+    } else if (SameFile) {
----------------
kadircet wrote:

nit: might be better to move this to the top, e.g:
```
auto *MD = dyn_cast...;
if (!MD)
  return !SameFile; // Can't outline free-standing functions in the same file.

// rest of the verification for methods
```

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


More information about the cfe-commits mailing list