Fix PCH bug with member templates of local classes in nontemplate functions.
authorFaisal Vali <faisalv@yahoo.com>
Wed, 26 Jun 2013 02:34:24 +0000 (02:34 +0000)
committerFaisal Vali <faisalv@yahoo.com>
Wed, 26 Jun 2013 02:34:24 +0000 (02:34 +0000)
commit18d3598ed0eb8b459a446cac037206caa4066208
tree55a1a62286aeb8f093da09a7d20c0feca6ca8a42
parent358256c77ad41d3502b4bdbc820a9598bc610ac7
Fix PCH bug with member templates of local classes in nontemplate functions.

As noted by Richard in the post:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20130624/082605.html, the following code should not add an entry
into PendingLocalImplicitInstantiations, since local instantiations
should only occur within the context of other instantiations:

int foo(double y) {
   struct Lambda {
      template<class T> T operator()(T t) const { return t; };
   } lambda;
   return lambda(y);
}

Hence the attached code does the following:
  1) In MarkFunctionReferenced, check if ActiveInstantiations.size()
      is non-zero before adding to PendingLocalImplicitInstantiations.
  2) In InstantiateFunctionDefinition, we swap out/in
      PendingLocalImplicitInstantiations so that only those
      pending local instantiations that are added during the instantiation
      of the current function are instantiated recursively.

llvm-svn: 184903
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/PCH/cxx-local-templates.cpp [new file with mode: 0644]
clang/test/PCH/cxx1y-local-templates.cpp [new file with mode: 0644]