llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: DeanSturtevant1

<details>
<summary>Changes</summary>

In DeclBase.h, clang::FunctionDecl is only forward-declared. Commit 
c9074cfd0d95 defined getEnclosingFunction() and castEnclosingFunction() inline 
in DeclBase.h, which instantiates dyn_cast&lt;FunctionDecl&gt; and 
cast&lt;FunctionDecl&gt; on an incomplete type when DeclBase.h is compiled 
standalone (e.g. with -fmodules / header units).

Move the non-const definitions to DeclBase.cpp where FunctionDecl is complete, 
and delegate the const overloads via const_cast, matching 
getOuterLexicalRecordContext() and getEnclosingNonExpansionStatementContext().


---
Full diff: https://github.com/llvm/llvm-project/pull/224711.diff


2 Files Affected:

- (modified) clang/include/clang/AST/DeclBase.h (+4-10) 
- (modified) clang/lib/AST/DeclBase.cpp (+8) 


``````````diff
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index a067d87e92a84..8ea2533825dd9 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -2198,20 +2198,14 @@ class DeclContext {
   /// In particular, this will return nullptr if the *nearest* enclosing
   /// DeclContext that is not an expansion statement is something other
   /// than a function (e.g. a CXXRecordDecl, even if it is a local class).
-  FunctionDecl *getEnclosingFunction() {
-    return dyn_cast<FunctionDecl>(getEnclosingNonExpansionStatementContext());
-  }
-
+  FunctionDecl *getEnclosingFunction();
   const FunctionDecl *getEnclosingFunction() const {
-    return dyn_cast<FunctionDecl>(getEnclosingNonExpansionStatementContext());
-  }
-
-  FunctionDecl *castEnclosingFunction() {
-    return cast<FunctionDecl>(getEnclosingNonExpansionStatementContext());
+    return const_cast<DeclContext *>(this)->getEnclosingFunction();
   }
 
+  FunctionDecl *castEnclosingFunction();
   const FunctionDecl *castEnclosingFunction() const {
-    return cast<FunctionDecl>(getEnclosingNonExpansionStatementContext());
+    return const_cast<DeclContext *>(this)->castEnclosingFunction();
   }
 
   /// Test whether the context supports looking up names.
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 70f61fa57a682..548643cea2cce 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -2096,6 +2096,14 @@ DeclContext 
*DeclContext::getEnclosingNonExpansionStatementContext() {
   return DC;
 }
 
+FunctionDecl *DeclContext::getEnclosingFunction() {
+  return dyn_cast<FunctionDecl>(getEnclosingNonExpansionStatementContext());
+}
+
+FunctionDecl *DeclContext::castEnclosingFunction() {
+  return cast<FunctionDecl>(getEnclosingNonExpansionStatementContext());
+}
+
 bool DeclContext::InEnclosingNamespaceSetOf(const DeclContext *O) const {
   // For non-file contexts, this is equivalent to Equals.
   if (!isFileContext())

``````````

</details>


https://github.com/llvm/llvm-project/pull/224711
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to