[PATCH][C++] Fix constant reference in a lambda (PR c++/53488)

Jason Merrill jason@redhat.com
Fri Feb 15 18:11:00 GMT 2013


Hi, thanks for your patch, and sorry it took me so long to respond.

On 08/18/2012 11:02 AM, Jiří Paleček wrote:
> The idea of the fix is to postpone the decision whether or not to
> capture later to the template instantiation. This is because until then,
> we cannot know if the variable fulfills the conditions for a constant
> expression or not. So the patch assumes that if the constant value is a
> VAR_DECL (which is what I've found to happen in the debugger, although
> I'm not sure this is the only case) and we are in a template
> declaration, it just leaves the id expression there as is.

Thanks, I've now committed a simpler version of this that doesn't even 
bother calling integral_constant_value in templates.

> Then the patch fiddles with the capture list in template instantiation
> code. Because new captures can be added while processing the template,
> we need to concatenate them with the original list from the template,
> plus there's a small hack to avoid producing the
> lambda-to-function-pointer conversion operator while we still don't have
> the final capture list.

I think a cleaner way to deal with the conversion issue would be to 
instantiate the capture list in instantiate_class_template_1 instead of 
here, so that we can do it in between the members and the conversion op.

> I have produced two tests (in the patch) and ran the testsuite in the
> gcc subdirectory successfully. I've also tested the behavior on a
> testcase in the attached test.cpp file (it should print ok with all
> possible combinations of #defined macros).

Could you adjust the testcase so that it will work in the testsuite?

Thanks,
Jason



More information about the Gcc-patches mailing list