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

Richard Smith richard at metafoo.co.uk
Tue Jun 25 19:18:04 PDT 2013


LGTM, thanks!

On Tue, Jun 25, 2013 at 7:02 PM, Faisal Vali <faisalv at gmail.com> wrote:
> 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



More information about the cfe-commits mailing list