[PATCH] Fix bug with member templates of local classes in nontemplate functions and PCHs

Faisal Vali faisalv at gmail.com
Tue Jun 25 19:02:26 PDT 2013


Richard,
  based on your guidance in:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20130624/082605.html
, attached is a patch that fixes a tinyish bug in template
instantiation that causes
an assertion violation during PCH writing, which assumes no local
implicit instantiations
are pending at the end of the translation unit.

As noted by Richard in the linked to post, the following code should
not add an entry
into PendingLocalImplicistInstantiations, 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.

Thanks!
Faisal Vali
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-pending-local-instantiations-for-pch.patch
Type: application/octet-stream
Size: 4624 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130625/98657eac/attachment.obj>


More information about the cfe-commits mailing list