llvm / llvm/llvm-project

[C23] Clang accepts redefinitions with compatible, not same, types for members

Open
#201,647 1 comment 0 reactions 0 assignees View on GitHub
accepts-invalid c23 clang:frontend confirmed
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

When implementing WG14 N3037, we missed this bit:

C23 6.7.3.4p1:
> ... If two declarations of the same type have a member-declaration or enumerator-list, one shall not be nested within the other and both declarations shall fulfill all requirements of compatible types (6.2.7) with the additional requirement that corresponding members of structure or union types shall have the same (and not merely compatible) types.

"not merely compatible" is the missing bit. That means we accept code like:

```c
enum E : int { e1 };

struct S1 {
enum E e;
};

struct S1 {
int e;
};
```

https://godbolt.org/z/P6hWd1jde

or

```c
enum F { first };
enum G { second };

struct S2 {
enum F f;
};

struct S2 {
enum G f;
};
```

https://godbolt.org/z/rjW6xb4do

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.