[clang] [clang-format] Stop fixing indentation on namespace closing brace (PR #122234)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 9 00:28:58 PST 2025
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/122234
Fixes #119790.
>From 38b8ebca922a7511d9f2bc048f3df0c9863cafc8 Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Thu, 9 Jan 2025 00:16:30 -0800
Subject: [PATCH] [clang-format] Stop fixing indentation on namespace closing
brace
Fixes #119790.
---
clang/lib/Format/UnwrappedLineFormatter.cpp | 2 +-
clang/unittests/Format/FormatTestSelective.cpp | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
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