[clang] f66d602 - [clang-format] Fix wrong indentation after trailing requires clause.
Marek Kurdej via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 22 23:22:16 PST 2021
Author: Marek Kurdej
Date: 2021-12-23T08:22:12+01:00
New Revision: f66d602c3f58bd8a312c79bb404eac9dabf1a730
URL: https://github.com/llvm/llvm-project/commit/f66d602c3f58bd8a312c79bb404eac9dabf1a730
DIFF: https://github.com/llvm/llvm-project/commit/f66d602c3f58bd8a312c79bb404eac9dabf1a730.diff
LOG: [clang-format] Fix wrong indentation after trailing requires clause.
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
````
Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan
Differential Revision: https://reviews.llvm.org/D116183
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 6010d276af05c..4f300bb63a42d 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1439,7 +1439,7 @@ void UnwrappedLineParser::parseStructuralElement(bool IsTopLevel) {
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)) {
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index a787e26ccd5ad..ee486f4521949 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -3556,6 +3556,11 @@ TEST_F(FormatTest, FormatsNamespaces) {
"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) {
More information about the cfe-commits
mailing list