[clang] [Clang] Fix a number of issues involving expansion statements (PR #217110)

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 20 04:09:08 PDT 2026


================
@@ -2188,6 +2188,30 @@ class DeclContext {
     }
   }
 
+  /// Test whether we're directly inside a function or method, but ignoring
+  /// any intervening expansion statements.
+  bool isInsideFunctionOrMethod() const {
+    return getEnclosingNonExpansionStatementContext()->isFunctionOrMethod();
+  }
+
+  /// Cast this to a FunctionDecl if it is one, ignoring any intervening
+  /// expansion statements. Returns nullptr if this is not a function.
+  FunctionDecl *getAsFunctionDecl() {
+    return dyn_cast<FunctionDecl>(getEnclosingNonExpansionStatementContext());
+  }
+
+  const FunctionDecl *getAsFunctionDecl() const {
+    return dyn_cast<FunctionDecl>(getEnclosingNonExpansionStatementContext());
+  }
+
+  FunctionDecl *castAsFunctionDecl() {
+    return cast<FunctionDecl>(getEnclosingNonExpansionStatementContext());
+  }
+
+  const FunctionDecl *castAsFunctionDecl() const {
+    return cast<FunctionDecl>(getEnclosingNonExpansionStatementContext());
+  }
----------------
cor3ntin wrote:

but the name is not - maybe `getEnclosingContextAsFunctionDecl()` ?

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


More information about the cfe-commits mailing list