<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62399>62399</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-format AlignConsecutiveAssignments with preprocessor directives not working correctly
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
andli197
</td>
</tr>
</table>
<pre>
It seems that clang-format is grouping many preprocessor directives when formatting code. Especially #else statements along with AlignConsecutiveAssignments.
.clang-format:
```
---
Language: Cpp
AlignConsecutiveAssignments: true
```
Code example:
```
#include <string>
const std::string GetName() {
#if _WIN32
constexpr static char kMyName[] = "Foo";
#else
constexpr static char kMyName[] = "NewName";
#endif
return kMyName;
}
int main() {
#if _WIN32
static constexpr char kVar[] = "MyFancyWindowsVariable";
#else
static constexpr char kVar[] = "MyOtherFancyVariable";
#endif
return 0;
}
```
Applying the style to the code above will render an alignment of the value for kVar[] in the #else-statement to be aligned with the variable assignment of kMyName[] from the #else-statement in the function GetName().
Renaming kMyName[] to a shorter name is causing the reformatting to follow this. And if the GetName method is completley removed no alignment is made, hence my suspicion that preprocessors else-statements are mixed up.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUlc-O2zYQxp-GugxsyJT876CDs46LAM0W6CE5FhQ5kthQpECO7NXbF6S8XjvNBgmwWFvU8MfvG86MRQi6tYgVW39g62MmRuqcr4RVRq_226x2aqo-EQTEPgB1gkAaYdtF43wvCHSA1rtx0LaFXtgJBo-DdxJDcB6U9ihJnzHApUML8yaKwdIpXMLHMKDUwpgJGC_QBIRAgrBHSwGEcbaFi6YODka39snZgHKMwEPSncKWLD-y_DD_X96rY8V1lW3y6196XCwW85c_hW1H0SIrDvA0DPPiT46KceRH_CH1ySkEfBH9YPC9kxkvtJVmVAiseArktW1Z8fHegXQ2EARSkVEc5hj4A-lZ9Mj4jvE9sO2HN14D_3z99F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