diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java index 67e41410bc7..c32706a779e 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java @@ -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) { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java index a2a490f85f4..459aab7aa09 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java @@ -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(); + } }