GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c++/modules

Defer completion of streamed-in cNTTPs in C++ modules

This commit defers the completion of streamed-in constant non-type template parameters (cNTTPs) in C++ modules to avoid lazy loading recursion.

This commit addresses a lazy loading recursion issue encountered when streaming in constant non-type template parameters (cNTTPs) in C++ modules. The issue arose because the class definition of involved template parameters might not have been streamed in yet. To resolve this, the commit defers calling cp_finish_decl for NTTP objects until after lazy loading has completed, mirroring the approach used for expand_or_defer_fn and constructors. This change ensures correct handling of cNTTPs in C++ modules.

In Details

This commit modifies module.cc and pt.cc to defer completion of streamed-in cNTTPs, specifically to avoid recursion via get_template_parm_object, cp_finish_decl, ensure_literal_type_for_constexpr_object, and complete_type. The fix involves pushing the result of get_template_parm_object to post_load_decls and processing them in post_load_processing. This is a follow-up to previous NTTP object streaming fixes.

For Context

C++ modules are a way to organize code into reusable units, similar to header files but with improved dependency management and compilation speed. Non-type template parameters allow you to pass constant values (like integers or pointers) as arguments to templates. This commit fixes a problem that could occur when using modules with non-type template parameters due to the order in which the compiler loads and processes the code. By delaying the processing of certain template parameters, the compiler can avoid errors and ensure that the code is compiled correctly.

Filed Under: c++modulestemplatesbugfix