Author: Marek Kurdej Date: 2021-12-20T09:13:32+01:00 New Revision: 960712ccc7103ded3d95e10c61516126836a1eba
URL: https://github.com/llvm/llvm-project/commit/960712ccc7103ded3d95e10c61516126836a1eba DIFF: https://github.com/llvm/llvm-project/commit/960712ccc7103ded3d95e10c61516126836a1eba.diff LOG: [clang-format] Fix wrong indentation of namespace identifiers after a concept declaration. Before this patch, the code: ``` template <class T> concept a_concept = X<>; namespace B { struct b_struct {}; } // namespace B ``` with config: ``` NamespaceIndentation: None ``` was wrongly indented inside namespace B, giving: ``` template <class T> concept a_concept = X<>; namespace B { struct b_struct {}; } // namespace B ``` Fixes https://github.com/llvm/llvm-project/issues/50645 Reviewed By: MyDeveloperDay, owenpan Differential Revision: https://reviews.llvm.org/D116008 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 c34d515a32d65..ccffa5959a662 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1438,7 +1438,7 @@ void UnwrappedLineParser::parseStructuralElement(bool IsTopLevel) { break; case tok::kw_concept: parseConcept(); - break; + return; case tok::kw_requires: parseRequires(); break; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 9325f622d228e..8287188a99717 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -3548,6 +3548,14 @@ TEST_F(FormatTest, FormatsNamespaces) { "} // namespace in\n" "} // namespace out", Style)); + + Style.NamespaceIndentation = FormatStyle::NI_None; + verifyFormat("template <class T>\n" + "concept a_concept = X<>;\n" + "namespace B {\n" + "struct b_struct {};\n" + "} // namespace B\n", + Style); } TEST_F(FormatTest, NamespaceMacros) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits