C/C++ editor style: line breaks in function calls

Answered

I am having trouble with CLion acting unexpectedly when inserting a newline after a comma in a function call.  Specifically, I have the Preferences->Editor Style->C / C++->"Wrapping and Braces"->Function Call Arguments->Align when Multline setting checked, which the preferences editor tells me should look like this:

Say I have the following piece of code:

int main(int argc, char* argv) {
printf("Received %d arguments.\n", argc);
}

If I select the character after the comma in the printf and hit return, then the code looks like this:

int main(int argc, char* argv) {
printf("Received %d arguments.\n",
argc);
}

This is different than the behavior that I would expect based on the the preferences dialog.  I would have expected the argc variable use to align with the first double quote.  Indeed if I reformat the file with code->reformat code, then it shows me the expected formatting:

int main(int argc, char *argv) {
printf("Received %d arguments.\n",
argc);
}

PyCharm's behavior for python code is that the second argument right after a newline will align with the first argument.  I could be misremembering, but I think this recently changed for CLion, because I thought it used to do the alignment the same way without having to reformat.  Am I misremembering, or has this changed?

My CLion details:

CLion 2019.2.5
Build #CL-192.7142.39, built on October 29, 2019
[[[license details removed]]]
Runtime version: 1.8.0_212-release-1586-b16 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6
GC: ParNew, ConcurrentMarkSweep
Memory: 1987M
Cores: 8
Registry: run.processes.with.pty=TRUE
Non-Bundled Plugins:
1
2 comments

I'm having the same problem. Why has this not gotten any reply from JetBrains in almost 6 months?

If "Align when multiple" is checked, a function argument in a new line (after hitting enter) should be aligned with the preceding argument, but it isn't.

The same is true for the "Align when multiple" check in "Function declaration parameters", it has no effect there either.

0

It seems to be related to https://youtrack.jetbrains.com/issue/CPP-12686. Feel free to comment or upvote.

0

Please sign in to leave a comment.