[clang] [clang-format] Fix qualifier ordering for lines after PP directives (PR #160731)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 25 11:45:33 PDT 2025


================
@@ -1195,6 +1195,41 @@ TEST_F(QualifierFixerTest, QualifiersBrokenUpByPPDirectives) {
                Style);
 }
 
+TEST_F(QualifierFixerTest, QualifierOrderingAfterPreprocessorDirectives) {
+  auto Style = getLLVMStyle();
+  Style.QualifierAlignment = FormatStyle::QAS_Custom;
+  Style.QualifierOrder = {"static", "inline", "const", "type"};
+
+  verifyFormat("#if 1\n"
+               "void foo(const int par);\n"
+               "const int var1;\n"
+               "#endif\n"
+               "\n"
+               "const int var2;\n"
+               "const int var3;\n",
+               "#if 1\n"
+               "void foo(int const par);\n"
+               "int const var1;\n"
+               "#endif\n"
+               "\n"
+               "int const var2;\n"
+               "int const var3;\n",
----------------
HazardyKnusperkeks wrote:

```suggestion
               "const int var3;",
               "#if 1\n"
               "void foo(int const par);\n"
               "int const var1;\n"
               "#endif\n"
               "\n"
               "int const var2;\n"
               "int const var3;",
```

https://github.com/llvm/llvm-project/pull/160731


More information about the cfe-commits mailing list