https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120776
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #61842|0 |1 is obsolete| | --- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Created attachment 61885 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61885&action=edit gcc16-pr120776-wip.patch Updated WIP patch. As the expansion-stmt2.C testcase shows, if expansion-init is dependent and during first tsubst_stmt of it not dependent, those cases seem to work quite well (will need to work on diagnostics for control-flow-limited statement, testcase for no labels in the body etc. Anyway, still have a couple of major issues: 1) the instantiation when not inside of a template works weirdly; this is because tsubst_expr has: else if (local_variable_p (t) && ((r = retrieve_local_specialization (t)) || TREE_CODE (t) == PARM_DECL || uses_template_parms (DECL_CONTEXT (t)))) for non-DECL_LOCAL_DECL_P VAR_DECLs without DECL_TEMPLATE_INFO. The code right now registers local specialization of the for-range-declaration (and structured bindings in there if any), but nothing else. As in non-templates uses_template_parms (DECL_CONTEXT (t)) is false, it means only for-range-declaration is locally specialized and the rest is used directly (except PARM_DECLs). Now, we want PARM_DECLs and VAR_DECLs defined outside of the TEMPLATE_FOR_STMT to map to themselves, but VAR_DECLs defined inside of the TEMPLATE_FOR_STMT to be specialized. Shall I use some flag next to this || uses_template_parms (e.g. instead of 1-bit scope_chain->expansion_stmt meant primarily for the control-flow-limited diagnostics use 2 bits to differentiate between non-template instantiation during parsing vs. the rest? 2) from the paper, it is unclear when the lowering of expansion statement needs to happen; it says that for-range-declaration is not type dependent if expansion-init of iterating expansion stmt is not type dependent and I think I handle that already doing auto deduction in that case. But is there some strong reason why the expansion statement would need to be lowered still when processing_template_decl? Not really sure how to (partially) instantiate it in that case 3) the TEMPLATE_FOR_STMT part doesn't have the if (!finish_expansion_stmt (...)) case implemented, I guess I can handle it easily, but I'm afraid I don't understand how to construct a testcase, where something is only partially instantiated and the expansion-initializer is still type-dependent during that instantiation and it will need another instantiation later on