问题
Using Ubuntu 16.04, Nsight Eclipse 10.4, Eclipse C/C++ Development Tools 8.4.0.nvidia-qualifier.
Working with C++ code.
Aim
I have created a new profile for the code formatter. Its intended outcome is correctly reproduced by the very IDE (Window > Preferences > C/C++ > Code Style > Formatter)
Result
However, when I format the source code accordingly, for example with Ctrl+Shift+F, the function signature is split into two lines. This is shown below in lines 30 and 31. This is undesirable because the custom style aims to return a format compatible with a remote repository. The code does compile, but adding new lines complicates the comparison with other branches terribly.
Research
I have exported the new formatting policy as an xml document, and the only instruction containing the keyword 'function' is:
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_identifier_in_function_declaration" value="do not insert"/>
which is what I want. So it looks like the IDE is ignoring/reverting the instruction given at the point of reading it in and/or applying it.
Way back in 2017, another OP reported a sort of similar difficulties in Eclipse/nsight formatter doesn't respect function body indentation policy
Way back in 2012, a very similar problem occurred for Eclipse C++ formatter puts new line before method identifiers; however, the tips given there do not work for me (possibly because paths have changed in this meantime?)
Comparison
After publication I also realised that the same inconsistency occurs for all built-in code styles (BSD/Allman, K&R, Gnu, Whitesmiths). So this problem is not strictly related to custom styles.
Question
Is there anything else I should look into? Is there a workaround to fix this?
来源:https://stackoverflow.com/questions/61257074/code-formatter-inserts-new-line-between-type-and-function-identifier-when-i-don