1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 16:55:38 +02:00

Bug 564273 - Fix format lambda expressions without parenthesis

Change-Id: I918ca05d75ca4e8cba7501e232d4e6b05e434f06
This commit is contained in:
Marco Stornelli 2020-06-14 09:28:14 +02:00
parent 72bf8216d8
commit f4bed34dd0
2 changed files with 25 additions and 6 deletions

View file

@ -1032,9 +1032,11 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
// declarator
final ICPPASTFunctionDeclarator declarator = node.getDeclarator();
skipNonWhitespaceToNode(declarator);
if (declarator != null) {
skipNonWhitespaceToNode(declarator);
}
boolean hasSpace = scribe.printComment();
boolean hasPointerOps = declarator.getPointerOperators().length > 0;
boolean hasPointerOps = declarator != null ? declarator.getPointerOperators().length > 0 : false;
boolean needSpace = (hasPointerOps && hasSpace) || (!hasPointerOps && peekNextToken() == Token.tIDENTIFIER);
if (needSpace) {
scribe.space();
@ -1047,11 +1049,13 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
preferences.insert_space_before_opening_brace_in_method_declaration, false);
scribe.setTailFormatter(tailFormatter);
}
declarator.accept(this);
if (declarator != null) {
declarator.accept(this);
IASTAttributeSpecifier[] attributes = declarator.getAttributeSpecifiers();
if (attributes.length > 0) {
formatAttributes(declarator, true, false);
IASTAttributeSpecifier[] attributes = declarator.getAttributeSpecifiers();
if (attributes.length > 0) {
formatAttributes(declarator, true, false);
}
}
if (tailFormatter != null) {

View file

@ -4825,4 +4825,19 @@ public class CodeFormatterTest extends BaseUITestCase {
public void testVariadicFunction_Bug487990() throws Exception {
assertFormatterResult();
}
//int main() {
// const int a = []{return 12;}();
// return 0;
//}
//int main() {
// const int a = [] {
// return 12;
// }();
// return 0;
//}
public void testLambdaWithoutParens_Bug564273() throws Exception {
assertFormatterResult();
}
}