https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124781
--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Nathaniel Shead <[email protected]>: https://gcc.gnu.org/g:c396fcf5ad4ad022b2b0638d7f1f80324d713458 commit r16-8486-gc396fcf5ad4ad022b2b0638d7f1f80324d713458 Author: Nathaniel Shead <[email protected]> Date: Sun Apr 5 23:26:32 2026 +1000 c++/modules: Only mark namespace-scope entities as exported [PR124781] We call 'set_originating_module' before we call pushdecl, which means that for function-scope entities we might not have set DECL_CONTEXT yet. Usually this doesn't matter, we only look at DECL_MODULE_EXPORT/ATTACH_P on namespace-scope entities to begin with, but in the case in the linked PR it causes issues because declarations in an unevaluated lambda appear to be in an internal context. Fixed by only considering non-null DECL_CONTEXT as being namespace scope within set_originating_module. As a drive-by improvement, ensured that we only talk about unnamed namespaces in the diagnostic within check_module_decl_linkage if we're actually within an anonymous namespace; this should be equivalent but will lead to a slightly clearer diagnostic if a similar bug crops up again later. PR c++/124781 gcc/cp/ChangeLog: * module.cc (set_originating_module): Add a function comment, only set attachment/exporting for entities with non-NULL DECL_CONTEXT. (check_module_decl_linkage): Use decl_anon_ns_mem_p instead of decl_internal_context_p. gcc/testsuite/ChangeLog: * g++.dg/modules/export-7.C: New test. Signed-off-by: Nathaniel Shead <[email protected]> Reviewed-by: Jason Merrill <[email protected]>
