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

    <tr>
        <th>Summary</th>
        <td>
            Add warning or diagnostic if a header file has unbalanced braces
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    If someone writes in a header file:
```
namespace foo {
...lots....
...of...
...code...
```
and forgets or miscounts the closing `}`s, the resulting compile errors can be very confusing. Particularly if the source file does `#include "buggy.h"` followed by `#include "other_header.h"`. Random name references deep in that other header will get interpreted from the wrong namespace. In the example I saw, the error manifested inside the STL, which is extra confusing.

Perhaps there should have a warning when a header file contains unbalanced braces, parens, etc. Alternatively, if worried about false positives from intentional mismatches (I don't think I've ever seen it...), it could just be a diagnostic/suggestion Clang shows if this happened and the compile failed in some other way. If there's an unbalanced header but it built anyway, it was probably intentional, though quite rude.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxtVMuO4zYQ_Br50ohgyx4_DjrM7mAAA3tYJLkHLbElcUORWj6s-O9TlB87uwkgSCKb7K6uKrJx6lqfOwpuFGeFZq-jBNKWmAZhJZ46baTYvhbrt2L9WuzX92cZWh4lTNwKdc5Rcfh0my7L0rgY8CmfE677OGqdkuf4l6RsFdL5XmIg52nUoXXJYhAHoda4oG1PefXhDe9QVJ-XiJeQTMyx1o0TQJN473ygli01QhfxV4Rsl3KCkr6yj7pNhr25ku6WHMEln5vJu5UDEblMtdW2NUkJFVXVpL6_lgP-EAJMY9wsiprrf5c6ZPR_3Vh87Cjpd7TnRsrMAXInXmyLQkpkyrTHgSMtOx_8z9oYAhmIRvGTl4h6nUeOjHj2Dh0_dSjpbJd5-YfHCV2cKfD8oGghhEa2upOQ02gbNMDm2B9_fsnL5kG3A-mABNHzB77uUi3vr-IHnhZBPEgbXDKKBr4IXDOzt1mEeZBfTJSTRUZJSrZhw-gbxHmgXjScGFQsfxLbkl4NurUc9UXMNc9Cotl5r7GJG5cidWyC0AQ_5EXhxkkmyUbtLJvsnJFjO2Qdq-MZitqiOkTA1vZvOuMfiAW-oCAAq2N2ZHVaikWgzV19SyFm9zApzb11AZ4pqvcAG4BC1KHP6KTPJMzhZiOQB3YmsRkpvLzY9m7JjvHOvC8n7i70zFfo1t3oBKqAbR85unPYoGfgapI2ESuu2HaHOnOgybuGm2zlHwzcdHepH-h7wsEmD2uWK1Vv1Wl74lXU0Uj9qtRTNdjjR5-5nZ8VHPh_xFslb-ohxinka6J6x9PrOKQGp3zEwJjL4_MbUH6TNmKoQ0hZ-PeX_e5wXA31y1btmm4jO3U6tlV7lKPsDw3zibtdddweVoYbMaEuXj4VL28rXVfrqlofNpvNaXParstmy7vTvjqqdbXf7UQVu7WMoLvMhUvcJytfLxhwhAOCRgdcUc8gh6B7K_LIzwnM-VrxRatG7GrBWy9g_wXfdcGv">