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.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150987 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaLambda.cpp b/lib/Sema/SemaLambda.cpp
index d1f87a2..6d54d40 100644
--- a/lib/Sema/SemaLambda.cpp
+++ b/lib/Sema/SemaLambda.cpp
@@ -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()) {
diff --git a/test/CodeGenCXX/lambda-expressions.cpp b/test/CodeGenCXX/lambda-expressions.cpp
index 6f0fa87..5a68e89 100644
--- a/test/CodeGenCXX/lambda-expressions.cpp
+++ b/test/CodeGenCXX/lambda-expressions.cpp
@@ -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