[clang] test (PR #101992)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 5 07:38:35 PDT 2024
https://github.com/Damien-Chen created https://github.com/llvm/llvm-project/pull/101992
None
>From ee5eb0eac6689fa0ab418218f5a6e76230a605d8 Mon Sep 17 00:00:00 2001
From: Damien-Chen <inkfan130924783 at gmail.com>
Date: Mon, 5 Aug 2024 22:36:47 +0800
Subject: [PATCH] Fix clang format
---
clang/lib/Format/TokenAnnotator.cpp | 7 +++----
clang/unittests/Format/FormatTest.cpp | 16 ++++++++++++++++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 4ed3e9d0e8e85..7d6dd3acc03a0 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3532,10 +3532,9 @@ void TokenAnnotator::setCommentLineLevels(
// Align comments for preprocessor lines with the # in column 0 if
// preprocessor lines are not indented. Otherwise, align with the next
// line.
- Line->Level = Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash &&
- PPDirectiveOrImportStmt
- ? 0
- : NextNonCommentLine->Level;
+ Line->Level = (PPDirectiveOrImportStmt && Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash)
+ ? NextNonCommentLine->Level
+ : 0;
} else {
NextNonCommentLine = Line->First->isNot(tok::r_brace) ? Line : nullptr;
}
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 2a754a29e81e7..e3556ca573202 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -5436,6 +5436,22 @@ TEST_F(FormatTest, IndentsPPDirectiveWithPPIndentWidth) {
" int y = 0;\n"
"}",
style);
+ verifyFormat("#ifndef PREDICTORS_HPP_\n"
+ "#define PREDICTORS_HPP_\n"
+ "int compute_prior(int column) {\n"
+ "#if defined(SPECIAL_PATH)\n"
+ " return top[column];\n"
+ "#else\n"
+ " // division-by-multiplication\n"
+ " #ifdef PEDANTIC\n"
+ " return prior(top[column]);\n",
+ " #else\n"
+ " return fast_prior(top[column]);\n"
+ " #endif\n"
+ "#endif\n"
+ "}\n"
+ "#endif // PREDICTORS_HPP_"
+ style);
style.IndentPPDirectives = FormatStyle::PPDIS_None;
verifyFormat("#ifdef foo\n"
More information about the cfe-commits
mailing list