Skip to content

[clang-format] Handle doxygen commands starting with \ #80381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 7, 2024
Merged

Conversation

XDeme1
Copy link
Contributor

@XDeme1 XDeme1 commented Feb 2, 2024

Fixes #63241

Doxygen commands can start with @ or \.

@llvmbot
Copy link
Member

llvmbot commented Feb 2, 2024

@llvm/pr-subscribers-clang-format

Author: Fernando Tagawa (XDeme)

Changes

Fixes llvm/llvm-project#63241

Doxygen commands can start with @ or \.


Full diff: https://github.com/llvm/llvm-project/pull/80381.diff

2 Files Affected:

  • (modified) clang/lib/Format/BreakableToken.cpp (+2-2)
  • (modified) clang/unittests/Format/FormatTestComments.cpp (+8)
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp
index 473908e8fee3b..75304908dc650 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -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;
diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp
index c249f4d9333fd..0327937e4496a 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -1909,6 +1909,14 @@ TEST_F(FormatTestComments, ReflowsComments) {
                    "// @param arg",
                    getLLVMStyleWithColumns(20)));
 
+  // Don't reflow lines starting with '\'.
+  EXPECT_EQ("// long long long\n"
+            "// long\n"
+            "// \\param arg",
+            format("// long long long long\n"
+                   "// \\param arg",
+                   getLLVMStyleWithColumns(20)));
+
   // Don't reflow lines starting with 'TODO'.
   EXPECT_EQ("// long long long\n"
             "// long\n"

@XDeme1 XDeme1 merged commit 1b03cbc into llvm:main Feb 7, 2024
@XDeme1 XDeme1 deleted the 63241 branch February 7, 2024 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clang-format fails to correctly format doxygen comments with \ as keyword starters
4 participants