Skip to content

Commit

Permalink
[clang-format] Handle doxygen commands starting with \ (#80381)
Browse files Browse the repository at this point in the history
Fixes #63241

Doxygen commands can start with `@` or `\`.
  • Loading branch information
XDeme1 committed Feb 7, 2024
1 parent 2f49058 commit 1b03cbc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clang/lib/Format/BreakableToken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,11 @@ const FormatToken &BreakableComment::tokenAt(unsigned LineIndex) const {

static bool mayReflowContent(StringRef Content) {
Content = Content.trim(Blanks);
// Lines starting with '@' commonly have special meaning.
// Lines starting with '@' or '\' commonly have special meaning.
// Lines starting with '-', '-#', '+' or '*' are bulleted/numbered lists.
bool hasSpecialMeaningPrefix = false;
for (StringRef Prefix :
{"@", "TODO", "FIXME", "XXX", "-# ", "- ", "+ ", "* "}) {
{"@", "\\", "TODO", "FIXME", "XXX", "-# ", "- ", "+ ", "* "}) {
if (Content.starts_with(Prefix)) {
hasSpecialMeaningPrefix = true;
break;
Expand Down
8 changes: 8 additions & 0 deletions clang/unittests/Format/FormatTestComments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1909,6 +1909,14 @@ TEST_F(FormatTestComments, ReflowsComments) {
"// @param arg",
getLLVMStyleWithColumns(20)));

// Don't reflow lines starting with '\'.
verifyFormat("// long long long\n"
"// long\n"
"// \\param arg",
"// long long long long\n"
"// \\param arg",
getLLVMStyleWithColumns(20));

// Don't reflow lines starting with 'TODO'.
EXPECT_EQ("// long long long\n"
"// long\n"
Expand Down

0 comments on commit 1b03cbc

Please sign in to comment.