[clang] [clang-format] Fix bad comment indentation before ifdef after braceless if (PR #94776)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 7 12:43:37 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 1b58940c88edaad9320bd21eaa7da65f7e791552 d5aca6de9f513ce049c337dc4c17ea32bb2721aa -- clang/lib/Format/UnwrappedLineParser.cpp clang/lib/Format/UnwrappedLineParser.h clang/unittests/Format/FormatTestComments.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index b17ef33f95..0263c0ded8 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -4835,9 +4835,8 @@ void UnwrappedLineParser::readToken(int LevelDifference) {
Line->Level += PPBranchLevel;
}
- if (!UnBracedBodyDepth) {
+ if (!UnBracedBodyDepth)
flushComments(isOnNewLine(*FormatTok));
- }
parsePPDirective();
PreviousWasComment = FormatTok->is(tok::comment);
diff --git a/clang/lib/Format/UnwrappedLineParser.h b/clang/lib/Format/UnwrappedLineParser.h
index 428c7dde18..4d87896870 100644
--- a/clang/lib/Format/UnwrappedLineParser.h
+++ b/clang/lib/Format/UnwrappedLineParser.h
@@ -338,7 +338,6 @@ private:
// `decltype(auto)`.
bool IsDecltypeAutoFunction = false;
-
int UnBracedBodyDepth = 0;
// Represents preprocessor branch type, so we can find matching
diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp
index e055a7c59f..2b7a45abf1 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -796,7 +796,6 @@ TEST_F(FormatTestComments, ParsesCommentsAdjacentToPPDirectives) {
format("namespace {}\n /* Test */ #define A"));
}
-
TEST_F(FormatTestComments, DeIdentsCommentBeforeIfdefAfterBracelessIf) {
EXPECT_EQ("void f() {\n"
" if (true)\n"
``````````
</details>
https://github.com/llvm/llvm-project/pull/94776
More information about the cfe-commits
mailing list