[PATCH] D121112: [clang-format] Fix namespace end comments in ObjC++ files too

Nico Weber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 7 06:44:47 PST 2022


thakis created this revision.
thakis added reviewers: MyDeveloperDay, zequanwu.
Herald added a project: All.
thakis requested review of this revision.

See also d96ae867351ec.


https://reviews.llvm.org/D121112

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


Index: clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
===================================================================
--- clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -416,6 +416,19 @@
                                     "// unrelated"));
 }
 
+TEST_F(NamespaceEndCommentsFixerTest, WorksForObjCpp) {
+  FormatStyle ObjCppStyle = getLLVMStyle();
+  ObjCppStyle.Language = FormatStyle::LK_ObjC;
+  EXPECT_EQ("namespace {\n"
+            "int i;\n"
+            "int j;\n"
+            "}// namespace",
+            fixNamespaceEndComments("namespace {\n"
+                                    "int i;\n"
+                                    "int j;\n"
+                                    "}", ObjCppStyle));
+}
+
 TEST_F(NamespaceEndCommentsFixerTest, AddsMacroEndComment) {
   FormatStyle Style = getLLVMStyle();
   Style.NamespaceMacros.push_back("TESTSUITE");
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23340,7 +23340,7 @@
 }
 
 TEST_F(FormatTest, VeryLongNamespaceCommentSplit) {
-  // These tests are not in NamespaceFixer because that doesn't
+  // These tests are not in NamespaceEndCommentsFixerTest because that doesn't
   // test its interaction with line wrapping
   FormatStyle Style = getLLVMStyleWithColumns(80);
   verifyFormat("namespace {\n"
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -3190,7 +3190,7 @@
       return BracesRemover(Env, Expanded).process();
     });
 
-  if (Style.Language == FormatStyle::LK_Cpp) {
+  if (Style.isCpp()) {
     if (Style.FixNamespaceComments)
       Passes.emplace_back([&](const Environment &Env) {
         return NamespaceEndCommentsFixer(Env, Expanded).process();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121112.413447.patch
Type: text/x-patch
Size: 1995 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220307/f33910c2/attachment-0001.bin>


More information about the cfe-commits mailing list