Improve our handling of lambda expressions that occur within default
arguments. There are two aspects to this:

  - Make sure that when marking the declarations referenced in a
  default argument, we don't try to mark local variables, both because
  it's a waste of time and because the semantics are wrong: we're not
  in a place where we could capture these variables again even if it
  did make sense.
  - When a lambda expression occurs in a default argument of a
  function template, make sure that the corresponding closure type is
  considered dependent, so that it will get properly instantiated. The
  second bit is a bit of a hack; to fix it properly, we may have to
  rearchitect our handling of default arguments, parsing them only
  after creating the function definition. However, I'd like to
  separate that work from the lambdas work.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151076 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaLambda.cpp b/lib/Sema/SemaLambda.cpp
index 694fee6..4204008 100644
--- a/lib/Sema/SemaLambda.cpp
+++ b/lib/Sema/SemaLambda.cpp
@@ -21,14 +21,16 @@
 using namespace clang;
 using namespace sema;
 
-CXXRecordDecl *Sema::createLambdaClosureType(SourceRange IntroducerRange) {
+CXXRecordDecl *Sema::createLambdaClosureType(SourceRange IntroducerRange,
+                                             bool KnownDependent) {
   DeclContext *DC = CurContext;
   while (!(DC->isFunctionOrMethod() || DC->isRecord() || DC->isFileContext()))
     DC = DC->getParent();
   
   // Start constructing the lambda class.
   CXXRecordDecl *Class = CXXRecordDecl::CreateLambda(Context, DC, 
-                                                     IntroducerRange.getBegin());
+                                                     IntroducerRange.getBegin(),
+                                                     KnownDependent);
   DC->addDecl(Class);
   
   return Class;
@@ -142,7 +144,14 @@
 void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
                                         Declarator &ParamInfo,
                                         Scope *CurScope) {
-  CXXRecordDecl *Class = createLambdaClosureType(Intro.Range);
+  // Determine if we're within a context where we know that the lambda will
+  // be dependent, because there are template parameters in scope.
+  bool KnownDependent = false;
+  if (Scope *TmplScope = CurScope->getTemplateParamParent())
+    if (!TmplScope->decl_empty())
+      KnownDependent = true;
+  
+  CXXRecordDecl *Class = createLambdaClosureType(Intro.Range, KnownDependent);
   
   // Determine the signature of the call operator.
   TypeSourceInfo *MethodTyInfo;