summaryrefslogtreecommitdiffstats
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
commit43c3f28c2328ebc96f356eb002d1bc8ff86c6324 (patch)
treec93fbf858daa9c0e52b2a36b74aff16a7f5135f6
parenta7765fea90294017b18b6a39cdc1a3531258d8c6 (diff)
downloadbcm5719-llvm-43c3f28c2328ebc96f356eb002d1bc8ff86c6324.tar.gz
bcm5719-llvm-43c3f28c2328ebc96f356eb002d1bc8ff86c6324.zip
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. llvm-svn: 150987
-rw-r--r--clang/lib/Sema/SemaLambda.cpp4
-rw-r--r--clang/test/CodeGenCXX/lambda-expressions.cpp3
2 files changed, 5 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index d1f87a2c189..6d54d403aa2 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/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/clang/test/CodeGenCXX/lambda-expressions.cpp b/clang/test/CodeGenCXX/lambda-expressions.cpp
index 6f0fa87bb14..5a68e893d71 100644
--- a/clang/test/CodeGenCXX/lambda-expressions.cpp
+++ b/clang/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
OpenPOWER on IntegriCloud