Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang-format closing bracket on a new line

I have code that looks like this:

EXPECT_EQ(
    subsystem->previousTouchscreenState,
    expectedTouchscreenState
);

When I run clang-format, it reformats the snippet to look like this:

EXPECT_EQ(
    subsystem->previousTouchscreenState,
    expectedTouchscreenState );

This is quite counterintuitive; I'd like my multi-line function invocations (although EXPECT_EQ is a macro in this case) to have the closing round bracket on its own line, indented to the level of the name of the function, as it is in the first snippet.

How do I accomplish this with clang-format?

Many thanks.

like image 891
sssilver Avatar asked Sep 04 '18 02:09

sssilver


2 Answers

I'd like my multi-line function invocations (although EXPECT_EQ is a macro in this case) to have the closing round bracket on its own line, indented to the level of the name of the function, as it is in the first snippet.

How do I accomplish this with clang-format?

That option does not seem to be added yet; either wait or get involved in the clang open source project.

Edit: As pointed out by Catskul, DCzajkowski and Dwayne in the comments: https://reviews.llvm.org/D109557 was accepted

like image 72
Andreas DM Avatar answered Nov 05 '22 21:11

Andreas DM


I found one workaround. If you put a comment at the end of the last argument, clang-format (or any tool) should not fold back the closing parenthesis.

EXPECT_EQ(
    subsystem->previousTouchscreenState,
    expectedTouchscreenState //
);
like image 2
Shriram V Avatar answered Nov 05 '22 21:11

Shriram V