Summary: Keep track of unpaired [] when identifying C# attribute lines
Reviewers: krasimir
Reviewed By: krasimir
Subscribers: cfe-commits
Tags: #clang-format, #clang
Differential Revision: https://reviews.llvm.org/D75455
}
void UnwrappedLineParser::parseCSharpAttribute() {
+ int UnpairedSquareBrackets = 1;
do {
switch (FormatTok->Tok.getKind()) {
case tok::r_square:
nextToken();
- addUnwrappedLine();
- return;
+ --UnpairedSquareBrackets;
+ if (UnpairedSquareBrackets == 0) {
+ addUnwrappedLine();
+ return;
+ }
+ break;
+ case tok::l_square:
+ ++UnpairedSquareBrackets;
+ nextToken();
+ break;
default:
nextToken();
break;
"{\n"
"}");
+ // [] in an attribute do not cause premature line wrapping or indenting.
+ verifyFormat(R"(//
+public class A
+{
+ [SomeAttribute(new[] { RED, GREEN, BLUE }, -1.0f, 1.0f)]
+ [DoNotSerialize]
+ public Data MemberVariable;
+})");
+
// Unwrappable lines go on a line of their own.
// 'target:' is not treated as a label.
// Modify Style to enforce a column limit.