https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127008
Bug ID: 127008
Summary: `if (type a(1))` should have a better error message
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
struct type1
{
type1(int);
};
void f(int a)
{
if (type1 s(a))
return;
}
```
Currently this gives:
```
<source>: In function 'void f(int)':
<source>:10:16: error: expected initializer before '(' token
10 | if (type1 s(a))
| ^
```
Which does not teach me that you can't have a parenthesized initializer in an
if stement.
Clang message is:
```
<source>:10:15: error: variable declaration in condition cannot have a
parenthesized initializer
10 | if (type1 s(a))
| ^~~~
```
Which is so much better and makes it easier to understand what is going wrong.
And I found this while writing GCC code :).