aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-02-20 20:47:06 +0000
committerDouglas Gregor <dgregor@apple.com>2012-02-20 20:47:06 +0000
commitfa07ab57eb565b4a00712adcefb29d96b445bfcd (patch)
tree6370b8641a1e4c937fe5dd16ece9ff17e88e6ce8
parentaf300298ab86752fa64e339ba34195888a830756 (diff)
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
-rw-r--r--lib/Sema/SemaLambda.cpp4
-rw-r--r--test/CodeGenCXX/lambda-expressions.cpp3
2 files changed, 5 insertions, 2 deletions
diff --git a/lib/Sema/SemaLambda.cpp b/lib/Sema/SemaLambda.cpp
index d1f87a2c18..6d54d403aa 100644
--- a/lib/Sema/SemaLambda.cpp
+++ b/lib/Sema/SemaLambda.cpp
@@ -28,7 +28,7 @@ CXXRecordDecl *Sema::createLambdaClosureType(SourceRange IntroducerRange) {
// 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 @@ CXXMethodDecl *Sema::startLambdaDefinition(CXXRecordDecl *Class,
// 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 6f0fa87bb1..5a68e893d7 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