llvm / llvm/llvm-project

[clang][modules]Missing redefinition error for enums from Global Module Fragment

Open
#190,768 6 comments 0 reactions 1 assignee Claimed by @ChuanqiXu9 View on GitHub
accepts-invalid clang:modules
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Summary

When a C++20 module's Global Module Fragment (GMF) defines an unscoped enum,
and a consumer translation unit imports that module then textually redefines
the same enum **twice**, Clang (on main/trunk) silently accepts both
redefinitions. The second redefinition should produce
`error: redefinition of 'Enum'`.

Release clang 21.x correctly diagnoses this.

## Reproducer

```
./run.sh
```

- `modA.cppm`: module whose GMF defines `enum Enum { ENUM };`
- `main.cc`: imports modA, then defines `enum Enum { ENUM };` twice

## Expected behavior

The first textual `enum Enum { ENUM };` is legitimate -- it's an ODR merge
with the hidden GMF definition. The second one should be diagnosed as a
redefinition error, just as it would be without the module import.

[redef.zip](https://github.com/user-attachments/files/26534244/redef.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.