https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127059
Bug ID: 127059
Summary: [modules] alias to closure type (decltype(lambda))
exported from a partition is not visible after 'import
:Partition;'
Product: gcc
Version: 16.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jasio.lpn at gmail dot com
Target Milestone: ---
Reduced from a larger project. A type alias to a lambda closure type
(`decltype([]{...})`), exported from a module partition, is not found
when the partition is imported from a sibling partition of the same
module — the compiler reports "does not name a type", as if the
`import :Partition;` had no effect.
Replacing the closure-type alias with an alias to a named struct with
operator() (equivalent semantics) resolves the issue, which suggests
the bug is specific to the interaction between module partitions and
closure types, not to partition imports in general.
=== decl.cppm ===
export module Test:Decl;
export namespace Test
{
using Fn = decltype([] (int) -> void {});
}
=== main-partition.cppm ===
export module Test:Main;
import :Decl;
export namespace Test
{
template <typename T = Fn>
struct Foo {};
}
=== test.cppm ===
export module Test;
export import :Decl;
export import :Main;
=== Command line ===
g++ -std=gnu++26 -fmodules-ts -x c++ -c decl.cppm -o decl.o
g++ -std=gnu++26 -fmodules-ts -x c++ -c main-partition.cppm -o main.o
=== Actual output ===
main-partition.cppm:6:28: error: 'Fn' does not name a type
6 | template <typename T = Fn>
| ^~
=== Workaround ===
Replacing the alias target with a named functor type resolves the
issue:
export namespace Test
{
struct FnImpl { auto operator()(int) const -> void {} };
using Fn = FnImpl;
}
This compiles and links without error, confirming the closure type
itself (not the partition-import mechanism in general) is the source
of the problem.
g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/16/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,cobol,algol68,lto
--prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugzilla.redhat.com/ --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --enable-libstdcxx-backtrace
--with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu
--enable-plugin --enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-16.2.1-build/gcc-16.2.1-20260819/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none,amdgcn-amdhsa --enable-offload-defaulted
--without-cuda-driver --enable-gnu-indirect-function --enable-cet
--with-tune=generic --with-tls=gnu2 --with-arch_32=i686
--build=x86_64-redhat-linux --with-build-config=bootstrap-lto
--enable-link-serialization=1 --disable-libssp
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.2.1 20260819 (Red Hat 16.2.1-2) (GCC)