<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/123573>123573</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format] Qualifiers are not sorted properly when `[[maybe_unused]]` or `[[nodiscard]]` attributes are used
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
lluisalemanypuig
</td>
</tr>
</table>
<pre>
I'm using clang-format 19
```
$ clang-format-19 --version
Ubuntu clang-format version 19.1.7 (++20250114103320+cd708029e0b2-1~exp1~20250114103432.75)
```
to format my C++ code. I specified the order of qualifiers in the following manner in my `.clang-format` file:
```
Language: Cpp
QualifierAlignment: Custom
QualifierOrder: [static, constexpr, inline, const, friend, type]
```
and it works well for functions and variable declarations when there are no attributes at the front:
```cpp
// the [[nodiscard]] attribute prevents clang-format from
// ordering the qualifiers 'constexpr' and 'static' properly.
[[nodiscard]] inline constexpr static int function_with_nodiscard() noexcept {
return 1;
}
// the attributes are ordered according to the specified order in the
// .clang-format file
static constexpr inline int function_without_nodiscard() noexcept { return 1; }
int main() {
// the [[maybe_unused]] attribute prevents clang-format from
// ordering the qualifiers 'constexpr' and 'static' properly.
[[maybe_unused]] constexpr static int A = 1234;
// the attributes are ordered according to the specified order in the
// .clang-format file
static constexpr int B = 1234;
}
```
I expected all the qualifiers to be ordered according to the predefined order in the file, so that they are ordered like this:
```cpp
[[nodiscard]] static constexpr inline int function_with_nodiscard() noexcept {
return 1;
}
static constexpr inline int function_without_nodiscard() noexcept { return 1; }
int main() {
[[maybe_unused]] static constexpr int A = 1234;
static constexpr int B = 1234;
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVktvqzgU_jXO5ijIGAhhwYI0ilRppNFdzLoycEI819iMH0mzub99ZKDNo-nVTGekK1Vq4NiH73Vkc2tFpxBLkm1Itl1w7w7alFJ6YbnE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