[clang] [clang-format] Handle doxygen commands starting with \ (PR #80381)
Fernando Tagawa via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 4 11:20:08 PST 2024
https://github.com/XDeme updated https://github.com/llvm/llvm-project/pull/80381
>From efd816282e5f5b71d6f88038a2121fa698becf7a Mon Sep 17 00:00:00 2001
From: XDeme <fernando.tagawa.gamail.com at gmail.com>
Date: Fri, 2 Feb 2024 00:27:57 -0300
Subject: [PATCH 1/2] [clang-format] Handle doxygen comments starting with \
---
clang/lib/Format/BreakableToken.cpp | 4 ++--
clang/unittests/Format/FormatTestComments.cpp | 8 ++++++++
2 files changed, 10 insertions(+), 2 deletions(-)
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"
>From cd291925afc7748e31e8be5d2eb484231fe64e24 Mon Sep 17 00:00:00 2001
From: XDeme <fernando.tagawa.gamail.com at gmail.com>
Date: Sun, 4 Feb 2024 16:19:57 -0300
Subject: [PATCH 2/2] Use verifyFormat
---
clang/unittests/Format/FormatTestComments.cpp | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp
index 0327937e4496a..d705cf34d8af0 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -1910,12 +1910,12 @@ TEST_F(FormatTestComments, ReflowsComments) {
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)));
+ 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"
More information about the cfe-commits
mailing list