https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99377
--- Comment #14 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Patrick Palka <ppa...@gcc.gnu.org>: https://gcc.gnu.org/g:2ceb4d531a303f3e70d8bb218c8759e6c0688f62 commit r13-3235-g2ceb4d531a303f3e70d8bb218c8759e6c0688f62 Author: Patrick Palka <ppa...@redhat.com> Date: Tue Oct 11 15:02:01 2022 -0400 c++ modules: lazy loading from within template [PR99377] Here when lazily loading the binding for f due to its first use from the template g, processing_template_decl is set which causes the call to note_vague_linkage_fn from module_state::read_cluster to have no effect, and thus we never push f onto deferred_fns and end up never emitting its definition despite needing it. The behavior of the lazy loading machinery shouldn't be sensitive to whether we're inside a template, so to that end this patch makes us clear processing_template_decl in the entrypoints lazy_load_binding and lazy_load_pendings. PR c++/99377 gcc/cp/ChangeLog: * module.cc (lazy_load_binding): Clear processing_template_decl. (lazy_load_pendings): Likewise. gcc/testsuite/ChangeLog: * g++.dg/modules/pr99377-2_a.C: New test. * g++.dg/modules/pr99377-2_b.C: New test.