[clang] 9db2a04 - [clang-format] Dont interpret variable named interface as keyword for C++
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 16 03:25:17 PDT 2023
Author: Jorge Pinto Sousa
Date: 2023-04-16T03:23:53-07:00
New Revision: 9db2a0454815979bc8e0f65e830ab9051b4ff5d2
URL: https://github.com/llvm/llvm-project/commit/9db2a0454815979bc8e0f65e830ab9051b4ff5d2
DIFF: https://github.com/llvm/llvm-project/commit/9db2a0454815979bc8e0f65e830ab9051b4ff5d2.diff
LOG: [clang-format] Dont interpret variable named interface as keyword for C++
Fixes #53173.
Differential Revision: https://reviews.llvm.org/D148437
Added:
Modified:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index e47d6342357cb..9158333911ae2 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 4b7fdddfdf7a0..c5c1f2150d3b1 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
More information about the cfe-commits
mailing list