[PATCH] D75747: [clang-format] Correct indentation for `[key] = value,` entries in C++ object initialisers
Phabricator via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 9 11:20:18 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcb3f20d27c9e: [clang-format] Correct indentation for `[key] = value,` entries in C++ object… (authored by Jonathan Coe <jbcoe at google.com>).
Changed prior to commit:
https://reviews.llvm.org/D75747?vs=249155&id=249172#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75747/new/
https://reviews.llvm.org/D75747
Files:
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTestCSharp.cpp
Index: clang/unittests/Format/FormatTestCSharp.cpp
===================================================================
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -551,6 +551,15 @@
Scaler = (Shape shape) => { return new Transform.Resize(shape, 0.1); },
};)",
Style);
+
+ // Dictionary initialisation.
+ verifyFormat(R"(//
+var myDict = new Dictionary<string, string> {
+ ["name"] = _donald,
+ ["age"] = Convert.ToString(DateTime.Today.Year - 1934),
+ ["type"] = _duck,
+};)",
+ Style);
}
TEST_F(FormatTestCSharp, CSharpNamedArguments) {
Index: clang/lib/Format/ContinuationIndenter.cpp
===================================================================
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1047,6 +1047,9 @@
if (NextNonComment->is(TT_ArraySubscriptLSquare)) {
if (State.Stack.back().StartOfArraySubscripts != 0)
return State.Stack.back().StartOfArraySubscripts;
+ else if (Style.isCSharp()) // C# allows `["key"] = value` inside object
+ // initializers.
+ return State.Stack.back().Indent;
return ContinuationIndent;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75747.249172.patch
Type: text/x-patch
Size: 1241 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200309/34fe5cfa/attachment.bin>
More information about the cfe-commits
mailing list