[cfe-commits] r150987 - in /cfe/trunk: lib/Sema/SemaLambda.cpp test/CodeGenCXX/lambda-expressions.cpp

Douglas Gregor dgregor at apple.com
Mon Feb 20 12:47:06 PST 2012


Author: dgregor
Date: Mon Feb 20 14:47:06 2012
New Revision: 150987

URL: http://llvm.org/viewvc/llvm-project?rev=150987&view=rev
Log:
Make sure that we set up the right declaration contexts when creating
and introducing the lambda closure type and its function call
operator. Previously, we assumed that the lambda closure type would
land directly in the current context, and not some parent context (as
occurs with linkage specifications). Thanks to Richard for the test case.

Modified:
    cfe/trunk/lib/Sema/SemaLambda.cpp
    cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp

Modified: cfe/trunk/lib/Sema/SemaLambda.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLambda.cpp?rev=150987&r1=150986&r2=150987&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLambda.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLambda.cpp Mon Feb 20 14:47:06 2012
@@ -28,7 +28,7 @@
   // Start constructing the lambda class.
   CXXRecordDecl *Class = CXXRecordDecl::CreateLambda(Context, DC, 
                                                      IntroducerRange.getBegin());
-  CurContext->addDecl(Class);
+  DC->addDecl(Class);
   
   return Class;
 }
@@ -65,7 +65,7 @@
   
   // Temporarily set the lexical declaration context to the current
   // context, so that the Scope stack matches the lexical nesting.
-  Method->setLexicalDeclContext(Class->getDeclContext());  
+  Method->setLexicalDeclContext(CurContext);  
   
   // Add parameters.
   if (!Params.empty()) {

Modified: cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp?rev=150987&r1=150986&r2=150987&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp Mon Feb 20 14:47:06 2012
@@ -3,6 +3,9 @@
 // CHECK: @var = internal global
 auto var = [](int i) { return i+1; };
 
+// CHECK: @cvar = global
+extern "C" auto cvar = []{};
+
 int a() { return []{ return 1; }(); }
 // CHECK: define i32 @_Z1av
 // CHECK: call i32 @_ZZ1avENKUlvE_clEv





More information about the cfe-commits mailing list