[clang] [clang][modules-driver] Add support for C++ named modules and `import std` (PR #193312)

Naveen Seth Hanig via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 22 01:20:00 PDT 2026


naveen-seth wrote:

> > This is because Clang does not yet handle imports correctly when a Clang module has the same name as the importing Standard C++ module. This will be fixed soon.
> 
> I am interested in this. I feel the current status consistent with my impression. Why do you think it is a clang bug? Instead of a user (build system) bug?

For a minimal reproducer, modify `clang/test/Modules/named-module-with-fmodules.cppm` such that the exported module from `A.cppm` is also named `foo`. This should crash.

A fix can be applied here, by checking that the `Existing` is not a named module.
https://github.com/llvm/llvm-project/blob/22bb938f873f321466654ac5d7e04ea87731407e/clang/lib/Lex/ModuleMap.cpp#L1848

I'll file a `good-first-issue` for this later today!

> > I’m not exactly sure yet where to add to the StandardCPlusPlusModules doc.
> 
> It is clang/docs/StandardCPlusPlusModules.rst

Oh sorry, I should have worded this better! I meant that I'm not yet sure how to go about adding this; if it should go somewhere in `[How to build projects using modules](https://clang.llvm.org/docs/StandardCPlusPlusModules.html#id17)[¶](https://clang.llvm.org/docs/StandardCPlusPlusModules.html#how-to-build-projects-using-modules) or in a section at the bottom.

> The title and the summary make me confused. The title said "add support for .. and import std" but the summary shows `import std` is not supported.

`import std` is supported, but when using it we currently also produce an object file from the `std.cppm` and link against it (as if we had `-static`). I'm working on a fix for this but would like to do it as a follow-up.

https://github.com/llvm/llvm-project/pull/193312


More information about the cfe-commits mailing list