[clang-format] Fix wrong indentation of namespace identifiers after a concept declara...
authorMarek Kurdej <marek.kurdej+llvm.org@gmail.com>
Mon, 20 Dec 2021 08:12:35 +0000 (09:12 +0100)
committerMarek Kurdej <marek.kurdej+llvm.org@gmail.com>
Mon, 20 Dec 2021 08:13:32 +0000 (09:13 +0100)
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

clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp

index c34d515..ccffa59 100644 (file)
@@ -1438,7 +1438,7 @@ void UnwrappedLineParser::parseStructuralElement(bool IsTopLevel) {
       break;
     case tok::kw_concept:
       parseConcept();
-      break;
+      return;
     case tok::kw_requires:
       parseRequires();
       break;
index 9325f62..8287188 100644 (file)
@@ -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) {