[PATCH] D116183: [clang-format] Fix wrong indentation after trailing requires clause.

Marek Kurdej via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 22 11:55:29 PST 2021


curdeius created this revision.
curdeius added reviewers: MyDeveloperDay, HazardyKnusperkeks, owenpan.
curdeius requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/52834.

Before this patch, clang-format would wrongly parse top-level entities (e.g. namespaces) and format:

  template<int I>
  constexpr void foo requires(I == 42) {}
  namespace ns {
  void foo() {}
  }  // namespace ns

into:

  

template<int I>
constexpr void foo requires(I == 42) {}
namespace ns {

  void foo() {}

}  // namespace ns

  with configuration:

NamespaceIndentation: None

  `


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116183

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
@@ -3556,6 +3556,11 @@
                "struct b_struct {};\n"
                "} // namespace B\n",
                Style);
+  verifyFormat("template <int I> constexpr void foo requires(I == 42) {}\n"
+               "namespace ns {\n"
+               "void foo() {}\n"
+               "} // namespace ns\n",
+               Style);
 }
 
 TEST_F(FormatTest, NamespaceMacros) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1439,7 +1439,7 @@
       return;
     case tok::kw_requires:
       parseRequires();
-      break;
+      return;
     case tok::kw_enum:
       // Ignore if this is part of "template <enum ...".
       if (Previous && Previous->is(tok::less)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116183.395915.patch
Type: text/x-patch
Size: 1031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211222/c53c3458/attachment.bin>


More information about the cfe-commits mailing list