<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62027>62027</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format] Inconsistent treatment of braces in macros
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
SRNissen
</td>
</tr>
</table>
<pre>
This is possibly related to another issue:
* [[clang-format] strange behavior for #define macro with braces #50023
](https://github.com/llvm/llvm-project/issues/50023)
I discovered this in a significantly more complicated piece of code but thankfully it reduces to a simple example :smiley:
With all macros expanded, the code looks like:
```c++
int main(int argc, char **argv) {
if (argc > 1)
return argc;
else
return 0;
}
```
With macros, before running default clang-format, it looks like
```c++
#define START {
#define END }
int main(int argc, char **argv) START
if (argc > 1)
return argc;
else
return 0;
END
```
(Which is also the *expected* look)
Unfortunately, after running clang format, it actually looks like:
```c++
#define START {
#define END }
int main(int argc, char **argv) START if (argc > 1) return argc;
else return 0;
END
```
Similarly, this code:
```c++
START
START
START
END
END
END
```
Becomes this code:
```c++
START
START
START
END
END
END
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8lc9vozoQx_8acxltZQxJyYFDummkvfSw7dOeBzOAX42NbJPX_PdPJj9Kktdqd7V6CAXiH8N3PjPjQe9Va4hKtnhgi02CY-isK5-_PynvySSVrfflS6c8KA-D9V5Veg-ONAaqIVhAY0NHDpT3I7FszfiG8dOvWMNk90FqNO2XxroeA1tswAeHpiWoqMOdsg4a64CJrKZGGYIepbPwjwodVA4l-Ti34FxkR8OLDRNFF8Lg4yfFloltq0I3VnfS9kxstd6dHl8GZ_8mGZjYTho9E9uDKbGai_0GtfLS7shFxyaPDSBEPKpREk3Qe-itI5C2H7SSE4FBkSSwDUhbE1RjgNCheW1GrfegAjiqx6g_kgKv-kET0BtOT5atfa807Vm2hrmUH9Fx1PrAwQO9DWhqqpn4CqGjw7e0ta8etHq9ob7kh1sy8RDvaRQAQJkAPSrDRBFf0bUympQdRvgxXOjaHRMrYPfzbQ0wUcTVwLJHSM_g4Hg5CqMzB3vZbCNpT8d_xyX8Yp7db64k31A4EIgqK2oifDcao0wLNTU46gAXmSW-RuYzMj-F5T3vnl_W319mzr_PPD5tZnJ_g-hk-s8yvVw5Q_v49BlXJoofnZJdrGjU3k4pxcSa3gaSIWbZekJ4VR9_mca6MBoMpPfRSWwCuXM8pjjARRxQhhFjHfxqqn4ckIto_ZmY_FcoPqX_y8CfVa80ugO16WSJBfzTVTvPnKssOl0fDJ9l3Q58rviBpO3jqfU_iv1A3_WSm6VnLUldZvUqW2FCZbosUp7lnC-TrkzzppJ5SpTmeZqldY5p3twv86oQMq-KNFGl4CLjOV_x1SITy7us4CtRN8h5TsWyqFjOqUel72JDubOuTaZWUi4FF_eJxoq0P3VQV05dpxpbz3KulQ_-fVtQQU-99rohfjPSGq98IBMgOMLQxzfbnBqgMsezMBmdLn-_9U2S_w0AAP__QOg75Q">