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

C++/modules: Handle noexcept and deduced auto when merging functions.

Fixes a return type issue when merging functions with instantiated noexcept specifiers and deduced return types in C++ modules.

When merging functions from streamed-in C++ modules with in-TU (translation unit) versions, GCC can prematurely update the return type, leading to issues with deduced return type checks. This patch narrowly propagates the instantiated noexcept specifier using build_exception_variant and ensures the function type isn’t stale during updates. This fixes PR125115.

In Details

When streaming in a function from a C++ module (e.g., data() from view_interface<int>), the streamed-in version might have its noexcept specifier already instantiated and its return type deduced. During merging with the in-TU version, is_matching_decl logic updates the in-TU version. The patch modifies trees_in::is_matching_decl in module.cc to propagate the instantiated noexcept specifier more narrowly, avoiding premature return type updates that interfere with deduced return type checks.

For Context

C++ modules allow you to import code from other files, similar to headers but with better isolation and compilation speed. When the compiler merges a function definition from a module with an existing definition in your code, it needs to reconcile properties like whether the function can throw exceptions (noexcept) and whether the return type was automatically deduced. This commit fixes an issue where the compiler was incorrectly handling these properties during the merge, which led to errors when using modules.

Filed Under: c++modulesnoexceptreturn type deduction