Skip to content

Commit 2ea34cd

Browse files
authored
[clang-format] Stop fixing indentation on namespace closing brace (#122234)
Fixes #119790.
1 parent f926bcf commit 2ea34cd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ unsigned UnwrappedLineFormatter::format(
14601460
bool ContinueFormatting =
14611461
TheLine.Level > RangeMinLevel ||
14621462
(TheLine.Level == RangeMinLevel && !PreviousRBrace &&
1463-
!TheLine.startsWith(tok::r_brace));
1463+
!TheLine.startsWith(TT_NamespaceRBrace));
14641464

14651465
bool FixIndentation = (FixBadIndentation || ContinueFormatting) &&
14661466
Indent != TheLine.First->OriginalColumn;

clang/unittests/Format/FormatTestSelective.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,17 @@ TEST_F(FormatTestSelective, WrongIndent) {
388388
" int j;\n" // Format here.
389389
"}",
390390
24, 0));
391+
EXPECT_EQ("namespace {\n"
392+
"class C {\n"
393+
" int i;\n"
394+
"};\n"
395+
"} // namespace",
396+
format("namespace {\n" // Format here.
397+
" class C {\n"
398+
" int i;\n"
399+
" };\n"
400+
"}",
401+
1, 0));
391402
}
392403

393404
TEST_F(FormatTestSelective, AlwaysFormatsEntireMacroDefinitions) {

0 commit comments

Comments
 (0)