[PATCH] D148437: [clang-format] Dont interpret variable named interface as keyword for C++

Jorge Pinto Sousa via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 15 15:54:19 PDT 2023


sousajo updated this revision to Diff 513945.
sousajo added a comment.

- removed `FormatStyle Style = getLLVMStyle();` as llvm is the default style


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148437/new/

https://reviews.llvm.org/D148437

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,14 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, InterfaceAsClassMemberName) {
+  constexpr StringRef Code("class Foo {\n"
+                           "  int interface;\n"
+                           "  Foo::Foo(int iface) : interface{iface} {}\n"
+                           "}\n");
+  verifyFormat(Code);
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1881,7 +1881,7 @@
         }
       }
 
-      if (FormatTok->is(Keywords.kw_interface)) {
+      if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
         if (parseStructLike())
           return;
         break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148437.513945.patch
Type: text/x-patch
Size: 1054 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230415/2cbeb062/attachment.bin>


More information about the cfe-commits mailing list