Issue 204632
Summary Clang asserts in ASTContext::setCurrentNamedModule after C++ named module conflicts with module map module
Labels
Assignees
Reporter hongtaihu
    ### Reproducer

`main.cpp`:

```cpp
export module M;
```

`module.modulemap`:

```text
module M {}
```

Run:

```bash
clang++ -x c++ -fsyntax-only -std=c++26 -fmodules \
  -fmodule-map-file=module.modulemap \
  main.cpp
```

I can also reproduce with `--target=x86_64-pc-win32`, but the target is not required.

### Actual result

Clang diagnoses the module redefinition, then asserts:

```text
main.cpp:1:15: error: redefinition of module 'M'
 1 | export module M;
      |               ^
module.modulemap:1:8: note: previously defined here
    1 | module M {}
      |        ^
clang++: .../clang/lib/AST/ASTContext.cpp:1173:
void clang::ASTContext::setCurrentNamedModule(clang::Module*):
Assertion `M->isNamedModule()` failed.
```

Top of the stack:

```text
clang::ASTContext::setCurrentNamedModule(clang::Module*)
clang::Sema::ActOnModuleDecl(...)
clang::Parser::ParseModuleDecl(...)
clang::Parser::ParseTopLevelDecl(...)
clang::ParseAST(...)
```

### Expected result

Clang should reject the conflicting module declaration/module-map module without asserting.

### Version

Reproduced with an assertions build:

```text
clang version 23.0.0git (https://github.com/llvm/llvm-project.git ae35674951e4d20d45ed6202e641976c9c055f22)
Build config: +assertions
```

### Notes

This looks related to module declaration recovery when a C++ named module declaration conflicts with an existing Clang module-map module of the same name. I also have a nearby single-file reproducer that reaches a `ModuleMap` assertion in the same `Sema::ActOnModuleDecl` path; I will file it separately and cross-link it because it may share the same root cause.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to