[clang] 2ea34cd - [clang-format] Stop fixing indentation on namespace closing brace (#122234)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 9 19:10:19 PST 2025
Author: Owen Pan
Date: 2025-01-09T19:10:15-08:00
New Revision: 2ea34cdf2ba86cd129633f2a01fb695c79c0fe11
URL: https://github.com/llvm/llvm-project/commit/2ea34cdf2ba86cd129633f2a01fb695c79c0fe11
DIFF: https://github.com/llvm/llvm-project/commit/2ea34cdf2ba86cd129633f2a01fb695c79c0fe11.diff
LOG: [clang-format] Stop fixing indentation on namespace closing brace (#122234)
Fixes #119790.
Added:
Modified:
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTestSelective.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index ec65fea6ec3df9..cee84fb1191abb 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1460,7 +1460,7 @@ unsigned UnwrappedLineFormatter::format(
bool ContinueFormatting =
TheLine.Level > RangeMinLevel ||
(TheLine.Level == RangeMinLevel && !PreviousRBrace &&
- !TheLine.startsWith(tok::r_brace));
+ !TheLine.startsWith(TT_NamespaceRBrace));
bool FixIndentation = (FixBadIndentation || ContinueFormatting) &&
Indent != TheLine.First->OriginalColumn;
diff --git a/clang/unittests/Format/FormatTestSelective.cpp b/clang/unittests/Format/FormatTestSelective.cpp
index 3ae70a15d359b2..624684c7a079b8 100644
--- a/clang/unittests/Format/FormatTestSelective.cpp
+++ b/clang/unittests/Format/FormatTestSelective.cpp
@@ -388,6 +388,17 @@ TEST_F(FormatTestSelective, WrongIndent) {
" int j;\n" // Format here.
"}",
24, 0));
+ EXPECT_EQ("namespace {\n"
+ "class C {\n"
+ " int i;\n"
+ "};\n"
+ "} // namespace",
+ format("namespace {\n" // Format here.
+ " class C {\n"
+ " int i;\n"
+ " };\n"
+ "}",
+ 1, 0));
}
TEST_F(FormatTestSelective, AlwaysFormatsEntireMacroDefinitions) {
More information about the cfe-commits
mailing list