summaryrefslogtreecommitdiff
path: root/clang/unittests
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2023-05-06 16:29:16 -0700
committerOwen Pan <owenpiano@gmail.com>2023-05-08 19:45:30 -0700
commita4c87f8ccaccc76fd7d1c6c2e639ca84b9ec7794 (patch)
treec89bb4413c94ab6ce3f343e5e86a038fdddfb193 /clang/unittests
parente494ebf9d09b1112dcf4f22984bdb51bbf5d8cd7 (diff)
downloadllvm-a4c87f8ccaccc76fd7d1c6c2e639ca84b9ec7794.tar.gz
[clang-format] Fix consecutive alignments in #else blocks
Since 3.8 or earlier, clang-format has been lumping all #else, #elif, etc blocks together when doing whitespace replacements and causing consecutive alignments across #else blocks. Commit c077975 partially addressed the problem but also triggered "regressions". This patch fixes the root cause of the problem and "reverts" c077975 (except for the unit tests). Fixes #36070. Fixes #55265. Fixes #60721. Fixes #61498. Differential Revision: https://reviews.llvm.org/D150057
Diffstat (limited to 'clang/unittests')
-rw-r--r--clang/unittests/Format/FormatTest.cpp45
-rw-r--r--clang/unittests/Format/FormatTestComments.cpp4
2 files changed, 47 insertions, 2 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 099a5cb91364..dc673934a3f1 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6367,6 +6367,51 @@ TEST_F(FormatTest, FormatAlignInsidePreprocessorElseBlock) {
"#endif\n"
"}",
Style);
+
+ verifyFormat("#if FOO\n"
+ "int a = 1;\n"
+ "#else\n"
+ "int ab = 2;\n"
+ "#endif\n"
+ "#ifdef BAR\n"
+ "int abc = 3;\n"
+ "#elifdef BAZ\n"
+ "int abcd = 4;\n"
+ "#endif",
+ Style);
+
+ verifyFormat("void f() {\n"
+ " if (foo) {\n"
+ "#if FOO\n"
+ " int a = 1;\n"
+ "#else\n"
+ " bool a = true;\n"
+ "#endif\n"
+ " int abc = 3;\n"
+ "#ifndef BAR\n"
+ " int abcd = 4;\n"
+ "#elif BAZ\n"
+ " bool abcd = true;\n"
+ "#endif\n"
+ " }\n"
+ "}",
+ Style);
+
+ verifyFormat("void f() {\n"
+ "#if FOO\n"
+ " a = 1;\n"
+ "#else\n"
+ " ab = 2;\n"
+ "#endif\n"
+ "}\n"
+ "void g() {\n"
+ "#if BAR\n"
+ " abc = 3;\n"
+ "#elifndef BAZ\n"
+ " abcd = 4;\n"
+ "#endif\n"
+ "}",
+ Style);
}
TEST_F(FormatTest, FormatHashIfNotAtStartOfLine) {
diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp
index 60e045059be8..6e5b5b2d68d8 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -2759,7 +2759,7 @@ TEST_F(FormatTestComments, AlignTrailingComments) {
// Checks an edge case in preprocessor handling.
// These comments should *not* be aligned
- EXPECT_NE( // change for EQ when fixed
+ EXPECT_EQ(
"#if FOO\n"
"#else\n"
"long a; // Line about a\n"
@@ -4316,7 +4316,7 @@ TEST_F(FormatTestComments, SplitCommentIntroducers) {
)",
format(R"(//
/\
-/
+/
)",
getLLVMStyleWithColumns(10)));
}