Issue 76937
Summary Misleading diagnostic for `-> struct {} {}` class definitions in trailing return types
Labels new issue
Assignees
Reporter Eisenwave
    ```cpp
auto foo() -> struct {} {}
```
https://godbolt.org/z/zqne175PE

### Actual Diagnostic
```none
<source>:1:15: error: declaration of anonymous struct must be a definition
    1 | auto foo() -> struct {} {}
      | ^
<source>:1:27: error: expected a type
    1 | auto foo() -> struct {} {}
      |                           ^
<source>:1:27: error: expected function body after function declarator
```
The first line of this error is misleading because `struct {}` is a class definition. However, a *class-specifier* cannot appear in this context, so clang appears to parse the first `{}` as the function body and `struct` as an elaborated-type-specifier or something.

### Expected Diagnostic
```none
<source>:1:15: error: class definition may not appear in a trailing return type
    1 | auto foo() -> struct {} {}
 |               ^
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to