https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124478
--- Comment #4 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:2b5392a5053a94bfdd0c0f4602363a5ed9cefe05 commit r16-8090-g2b5392a5053a94bfdd0c0f4602363a5ed9cefe05 Author: Nathaniel Shead <[email protected]> Date: Sat Mar 14 02:23:09 2026 +1100 c++/modules: Support loading a lazy member while trying to declare it [PR124478] The testcase shows an issue where we end up indirectly loading a special member function while we're attempting to lazily declare it. This causes errors in the install_implicit_member because CLASSTYPE_LAZY* has been cleared, so it assumes that the member exists already. There are a few options to approach this issue: 1. Remove the error when we fail with install_implicit_member, and just silently assume that a case like this is happening. This should be safe, but could make it harder to understand future issues in this area. 2. Put all implicitly declared special members on the pending list for the class type, and add calls to lazy_load_pendings at the start of lazily_declare_fn and check if the functions have now been provided. But this could unnecessarily bloat out the pending tables as aggregate types used in lots of modules will add their special members to every module's pending table. 3. Detect exactly this special case in implicitly_declare_fn and halt processing. This should only impact lazily_declare_fn, but makes its API more complex. This patch takes option three. Just because we know that the function has been lazily declared somewhere else doesn't mean we can easily find its declaration, however; luckily nothing actually uses the return type of lazily_declare_fn, so we can change that to void instead and save on some effort. PR c++/124478 gcc/cp/ChangeLog: * cp-tree.h (lazily_declare_fn): Make return type void. * method.cc (is_lazy_special_member): New function. (implicitly_declare_fn): Bail early if we lazy loaded the member we're trying to declare. (lazily_declare_fn): Likewise. gcc/testsuite/ChangeLog: * g++.dg/modules/imp-member-6_a.C: New test. * g++.dg/modules/imp-member-6_b.C: New test. * g++.dg/modules/imp-member-6_c.C: New test. Signed-off-by: Nathaniel Shead <[email protected]> Reviewed-by: Jason Merrill <[email protected]>
