Author: Timm Baeder
Date: 2026-01-29T06:16:25+01:00
New Revision: 0d562c96689de6bce7ca06bd1890724c72d9c536

URL: 
https://github.com/llvm/llvm-project/commit/0d562c96689de6bce7ca06bd1890724c72d9c536
DIFF: 
https://github.com/llvm/llvm-project/commit/0d562c96689de6bce7ca06bd1890724c72d9c536.diff

LOG: [clang][bytecode] Only check static lambda captures if we have to (#178452)

Call `getCaptureFields()` only if the function is static, because we
only care about the captures in that case.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Context.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Context.cpp 
b/clang/lib/AST/ByteCode/Context.cpp
index 208fcb2a2732e..5d5816eb02cd2 100644
--- a/clang/lib/AST/ByteCode/Context.cpp
+++ b/clang/lib/AST/ByteCode/Context.cpp
@@ -555,15 +555,15 @@ const Function *Context::getOrCreateFunction(const 
FunctionDecl *FuncDecl) {
       // the lambda captures.
       if (!MD->getParent()->isCompleteDefinition())
         return nullptr;
-      llvm::DenseMap<const ValueDecl *, FieldDecl *> LC;
-      FieldDecl *LTC;
+      if (MD->isStatic()) {
+        llvm::DenseMap<const ValueDecl *, FieldDecl *> LC;
+        FieldDecl *LTC;
 
-      MD->getParent()->getCaptureFields(LC, LTC);
-
-      if (MD->isStatic() && !LC.empty()) {
+        MD->getParent()->getCaptureFields(LC, LTC);
         // Static lambdas cannot have any captures. If this one does,
         // it has already been diagnosed and we can only ignore it.
-        return nullptr;
+        if (!LC.empty())
+          return nullptr;
       }
     }
   }


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

Reply via email to