[clang] [clang-format] Fix InsertBraces inserting braces around directives (PR #224947)

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 26 01:00:50 PDT 2026


================
@@ -195,6 +195,51 @@ TEST_F(BracesInserterTest, InsertBraces) {
                "#endif",
                Style);
 
+  verifyFormat("if (a)\n"
+               "  if (b)\n"
+               "#ifdef A\n"
+               "    f();\n"
+               "#else\n"
+               "    g();\n"
+               "#endif",
+               Style);
+
+  verifyFormat("while (a)\n"
+               "  if (b)\n"
+               "    f(\n"
+               "#ifdef A\n"
+               "        1);\n"
+               "#else\n"
+               "        2);\n"
+               "#endif",
+               Style);
+
+  verifyFormat("if (a)\n"
+               "  f(\n"
+               "#ifdef A\n"
+               "      1\n"
+               "#else\n"
+               "      2\n"
+               "#endif\n"
+               "  );",
----------------
owenca wrote:

This is a regression. The braces should definitely be inserted here because the directives are not at the beginning/end of the unbraced body.

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


More information about the cfe-commits mailing list