Skip to content

Commit 9db2a04

Browse files
sousajo-ccowenca
authored andcommitted
[clang-format] Dont interpret variable named interface as keyword for C++
Fixes #53173. Differential Revision: https://reviews.llvm.org/D148437
1 parent 822f0de commit 9db2a04

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,7 @@ void UnwrappedLineParser::parseStructuralElement(
18811881
}
18821882
}
18831883

1884-
if (FormatTok->is(Keywords.kw_interface)) {
1884+
if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
18851885
if (parseStructLike())
18861886
return;
18871887
break;

clang/unittests/Format/FormatTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25429,6 +25429,13 @@ TEST_F(FormatTest, SpaceAfterUDL) {
2542925429
verifyFormat("auto x = 5s .count() == 5;");
2543025430
}
2543125431

25432+
TEST_F(FormatTest, InterfaceAsClassMemberName) {
25433+
verifyFormat("class Foo {\n"
25434+
" int interface;\n"
25435+
" Foo::Foo(int iface) : interface{iface} {}\n"
25436+
"}");
25437+
}
25438+
2543225439
} // namespace
2543325440
} // namespace test
2543425441
} // namespace format

0 commit comments

Comments
 (0)