Skip to content

[clang-format] Unexpected formatting on function parameter #91771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
LinZhihao-723 opened this issue May 10, 2024 · 2 comments
Open

[clang-format] Unexpected formatting on function parameter #91771

LinZhihao-723 opened this issue May 10, 2024 · 2 comments

Comments

@LinZhihao-723
Copy link

clang-format version: 18.1
Config file: https://github.com/LinZhihao-723/clp/blob/lint-update/components/core/.clang-format
Formatting output: https://github.com/LinZhihao-723/clp/blob/lint-update/components/core/src/clp/ir/LogEventDeserializer.cpp#L13
Formatted result:

template <typename encoded_variable_t>
auto LogEventDeserializer<encoded_variable_t>::create(ReaderInterface& reader
) -> BOOST_OUTCOME_V2_NAMESPACE::std_result<LogEventDeserializer<encoded_variable_t>> {

Expected result:

template <typename encoded_variable_t>
auto LogEventDeserializer<encoded_variable_t>::create(
        ReaderInterface& reader
) -> BOOST_OUTCOME_V2_NAMESPACE::std_result<LogEventDeserializer<encoded_variable_t>> {

Result from clang-format 17:

template <typename encoded_variable_t>
auto LogEventDeserializer<encoded_variable_t>::create(ReaderInterface& reader)
        -> BOOST_OUTCOME_V2_NAMESPACE::std_result<LogEventDeserializer<encoded_variable_t>> {

Not sure if this is a bug or missing configuration in .clang-format. Would be appreciated if someone can help take a look :D

@rymiel
Copy link
Member

rymiel commented Jun 25, 2024

I bisected this to e00d32a, which is meant to be an NFC commit, which is slightly concerning

Looking at debug output, two lines are different:
The very first token (template) used to be

 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=template L=8 PPK=2 FakeLParens= FakeRParens=0 Text='template'

and now is

 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=template L=8 PPK=2 FakeLParens=1/ FakeRParens=0 Text='template'

the difference being FakeLParens

and the arrow token (->) used to be

 M=0 C=1 T=TrailingReturnArrow S=1 F=0 B=0 BK=0 P=23 Name=arrow L=215 PPK=2 FakeLParens= FakeRParens=0 Text='->'

and is now

 M=0 C=1 T=TrailingReturnArrow S=1 F=0 B=0 BK=0 P=130 Name=arrow L=215 PPK=2 FakeLParens= FakeRParens=0 Text='->'

the difference being the SplitPenalty (P)

@rymiel
Copy link
Member

rymiel commented Aug 21, 2024

ccae7b4 has changed the output of this to now be:

template <typename encoded_variable_t>
auto LogEventDeserializer<encoded_variable_t>::create(
        ReaderInterface& reader
) -> BOOST_OUTCOME_V2_NAMESPACE::std_result<LogEventDeserializer<encoded_variable_t>> {

..which is exactly what's listed as "expected behavior" in the original bug report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants