diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp --- a/clang/lib/Format/Format.cpp +++ b/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(); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -23347,7 +23347,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" diff --git a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp --- a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp +++ b/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");