<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58355>58355</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang handles variable declaration with unknown type poorly
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          urazoff
      </td>
    </tr>
</table>

<pre>
    For a given code in `foo.c` file
```c
int foo() {
  some_type *bar;
}
```
`clang` gives a cascade of confusing diagnostics:
```
foo.c:2:3: error: use of undeclared identifier 'some_type'
  some_type *bar;
  ^
foo.c:2:12: error: use of undeclared identifier 'bar'
  some_type *bar;
```

and AST does not have a node with corresponding invalid `VarDecl`. So `clang` parser does not handle this code as variable declaration.

`gcc` gives far better diagnostics:
```
foo.c: In function 'foo':
foo.c:2:3: error: unknown type name 'some_type'
    2 |   some_type *bar;
      |   ^~~~~~~~~
```

In case of `foo.cpp` `clang` works pretty well:
```
foo.c: In function 'foo':
foo.c:2:3: error: unknown type name 'some_type'
    2 |   some_type *bar;
      |   ^~~~~~~~~
```

So `some_type` is handled as unknown type and this code is handled as although invalid but variable declaration.

The above behavior remains for variable declaration without `*` declarator.

Suggestion is to make `clang` handle this case consistently for C and C++ code. It will give better diagnostics for users and AST will have invalid declaration nodes and declaration reference nodes to this invalid declarations under `RecoveryExpr`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlVE1zmzAQ_TVw2SmDwWD7wMGxk5lcm06vHYEWrEaWGEnYdX99VyL-Sp2PnusRRkLS7tu3b7fW_FA9aAMMOrFDBY3mCEJBVKat1klDb2iFxChdR-mSVuNoxrVQDuhYlM2jbAHR7G78DGD1Fn-4Q48QZcuamSh_2Ypm61emTstGMtV5fx6JJUQNsw0jOLolWKodrFAdcME6pa0TjY3y5U1bI_B8mdGT0wNojDZ-MthgbVAcyZtBD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