[PATCH] D130417: [clang-format] Missing space between trailing return type 'auto' and left brace
Aleksandr Platonov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 28 14:32:01 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4977fd2192fc: [clang-format] Missing space between trailing return type 'auto' and left brace (authored by denis-fatkulin, committed by ArcsinX).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130417/new/
https://reviews.llvm.org/D130417
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23550,6 +23550,16 @@
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();
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3310,6 +3310,11 @@
}
}
+ // 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130417.448440.patch
Type: text/x-patch
Size: 1396 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220728/971d4860/attachment.bin>
More information about the cfe-commits
mailing list