Issue 123573
Summary [clang-format] Qualifiers are not sorted properly when `[[maybe_unused]]` or `[[nodiscard]]` attributes are used
Labels clang-format
Assignees
Reporter lluisalemanypuig
    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;
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to