[clang] 4977fd2 - [clang-format] Missing space between trailing return type 'auto' and left brace
Aleksandr Platonov via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 28 14:31:53 PDT 2022
Author: Denis Fatkulin
Date: 2022-07-29T00:30:22+03:00
New Revision: 4977fd2192fc13e17ea162da15ddbe17cd623757
URL: https://github.com/llvm/llvm-project/commit/4977fd2192fc13e17ea162da15ddbe17cd623757
DIFF: https://github.com/llvm/llvm-project/commit/4977fd2192fc13e17ea162da15ddbe17cd623757.diff
LOG: [clang-format] Missing space between trailing return type 'auto' and left brace
There's no a space symbol between trailing return type `auto` and left brace `{`.
The simpliest examles of code to reproduce the issue:
```
[]() -> auto {}
```
and
```
auto foo() -> auto {}
```
Depends on D130299
Reviewed By: HazardyKnusperkeks, curdeius, owenpan
Differential Revision: https://reviews.llvm.org/D130417
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 5991cf23d5dc7..6b65b69caa09a 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3310,6 +3310,11 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
}
}
+ // trailing return type 'auto': []() -> auto {}, auto foo() -> auto {}
+ if (Left.is(tok::kw_auto) &&
+ Right.isOneOf(TT_LambdaLBrace, TT_FunctionLBrace))
+ return true;
+
// auto{x} auto(x)
if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
return false;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index e26cfb0ee88a0..d15c38f291ac2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -23550,6 +23550,16 @@ TEST_F(FormatTest, AmbersandInLamda) {
verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
}
+TEST_F(FormatTest, TrailingReturnTypeAuto) {
+ FormatStyle Style = getLLVMStyle();
+ verifyFormat("[]() -> auto { return Val; }", Style);
+ verifyFormat("[]() -> auto * { return Val; }", Style);
+ verifyFormat("[]() -> auto & { return Val; }", Style);
+ verifyFormat("auto foo() -> auto { return Val; }", Style);
+ verifyFormat("auto foo() -> auto * { return Val; }", Style);
+ verifyFormat("auto foo() -> auto & { return Val; }", Style);
+}
+
TEST_F(FormatTest, SpacesInConditionalStatement) {
FormatStyle Spaces = getLLVMStyle();
Spaces.IfMacros.clear();
More information about the cfe-commits
mailing list