Author: Nico Weber Date: 2022-03-07T13:30:25-05:00 New Revision: e6a8b92b8959b17a140a30b340dd59cfa8781dea
URL: https://github.com/llvm/llvm-project/commit/e6a8b92b8959b17a140a30b340dd59cfa8781dea DIFF: https://github.com/llvm/llvm-project/commit/e6a8b92b8959b17a140a30b340dd59cfa8781dea.diff LOG: [clang-format] Fix namespace end comments in ObjC++ files too See also d96ae867351ec. Differential Revision: https://reviews.llvm.org/D121112 Added: Modified: clang/lib/Format/Format.cpp clang/unittests/Format/FormatTest.cpp clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 497ebb414384f..6c2765c038436 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -3190,7 +3190,7 @@ reformat(const FormatStyle &Style, StringRef Code, 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 index 1f8601d30857c..1d9b158ee6475 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -23347,7 +23347,7 @@ TEST_F(FormatTest, WhitespaceSensitiveMacros) { } 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 index e2ce6071c6e87..5b98590a65554 100644 --- a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp +++ b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp @@ -416,6 +416,19 @@ TEST_F(NamespaceEndCommentsFixerTest, AddsEndComment) { "// 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"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits