From: Jorge Pinto Sousa Date: Sun, 16 Apr 2023 10:17:40 +0000 (-0700) Subject: [clang-format] Dont interpret variable named interface as keyword for C++ X-Git-Tag: upstream/17.0.6~11464 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9db2a0454815979bc8e0f65e830ab9051b4ff5d2;p=platform%2Fupstream%2Fllvm.git [clang-format] Dont interpret variable named interface as keyword for C++ Fixes #53173. Differential Revision: https://reviews.llvm.org/D148437 --- diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index e47d634..9158333 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1881,7 +1881,7 @@ void UnwrappedLineParser::parseStructuralElement( } } - if (FormatTok->is(Keywords.kw_interface)) { + if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) { if (parseStructLike()) return; break; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 4b7fddd..c5c1f21 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -25429,6 +25429,13 @@ TEST_F(FormatTest, SpaceAfterUDL) { verifyFormat("auto x = 5s .count() == 5;"); } +TEST_F(FormatTest, InterfaceAsClassMemberName) { + verifyFormat("class Foo {\n" + " int interface;\n" + " Foo::Foo(int iface) : interface{iface} {}\n" + "}"); +} + } // namespace } // namespace test } // namespace format