https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120776
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Regarding 1), I think the problem is that if there are automatic vars defined in the expansion stmt body, there is no DECL_EXPR created for them. The problem is start_decl doing: 6214 if (processing_template_decl) 6215 decl = push_template_decl (decl); There is ++processing_template_decl around parsing of the expansion stmt bodies, but push_template_decl then does: 5893 if (decl == error_mark_node || !current_template_parms) 5894 return error_mark_node; and because I haven't created current_template_parms if expansion stmt is not inside of a template, this returns error_mark_node and a lot of things break because of that obviously. So probably I need to arrange for current_template_parms to be set and restored back as well.