| Issue |
178330
|
| Summary |
Compound literals and definitions of objects with incomplete type are incorrectly allowed when the type is completed in the initializer
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
Halalaluyafail3
|
The following program demonstrates the issue:
```c
int main(){
struct A a={(struct A{int x;}){}.x};
(struct B){(struct B{int y;}){}.y};
}
```
Clang appears to allow definitions of objects with incomplete type, so long as the first init declarator has an initializer wherein the type is completed. Same with compound literals, if the type is incomplete and the braced initializer completes the type then clang allows it. GCC rejects both, the latter only with -pedantic-errors. MSVC rejects both. I think this should not be allowed, since a can be referenced before the definition appears. Compare with something like:
```c
struct C c[sizeof(struct C{int z;})];
```
Here `c` cannot be named until after the type is completed, so it makes more sense to allow this. GCC and MSVC also allow this, though the standard is not clear as to whether this is supposed to be allowed. Same with type names:
```c
sizeof(struct D[sizeof(struct D{int w;})]);
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs