[clang] [clang-format] Fix repeated backslash insertion in macro line comments (PR #164300)
Björn Schäpers via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 20 12:58:14 PDT 2025
================
@@ -839,6 +839,25 @@ TEST_F(FormatTestComments, MultiLineCommentsInDefines) {
getLLVMStyleWithColumns(17)));
}
+TEST_F(FormatTestComments, LineCommentsInMacrosDoNotGetEscapedNewlines) {
+ FormatStyle Style = getLLVMStyleWithColumns(0);
+ Style.ReflowComments = FormatStyle::RCS_Never;
+ verifyFormat("#define FOO (1U) // comment\n"
+ " // comment",
+ Style);
+
+ Style.ColumnLimit = 32;
+ EXPECT_EQ("#define SOME_MACRO(x) x\n"
+ "#define FOO \\\n"
+ " SOME_MACRO(1) + \\\n"
+ " SOME_MACRO(2) // comment\n"
+ " // comment",
+ format("#define SOME_MACRO(x) x\n"
+ "#define FOO SOME_MACRO(1) + SOME_MACRO(2) // comment\n"
+ " // comment",
+ Style));
----------------
HazardyKnusperkeks wrote:
```suggestion
verifyFormat("#define SOME_MACRO(x) x\n"
"#define FOO \\\n"
" SOME_MACRO(1) + \\\n"
" SOME_MACRO(2) // comment\n"
" // comment",
"#define SOME_MACRO(x) x\n"
"#define FOO SOME_MACRO(1) + SOME_MACRO(2) // comment\n"
" // comment",
Style);
```
We have the 3 argument `verifyFormat`, the other tests are from a time where we hadn't. See also #164310.
https://github.com/llvm/llvm-project/pull/164300
More information about the cfe-commits
mailing list