Skip to content
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

[clang-format] AllowShortFunctionsOnASingleLine=Inline does not respect macros #133089

Closed
rafzi opened this issue Mar 26, 2025 · 2 comments
Closed
Labels
clang-format question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Comments

@rafzi
Copy link
Member

rafzi commented Mar 26, 2025

I stumbled upon #60627 which describes this same issue. Over there, the conclusion seems to be wont-fix because the intention of the related change (https://reviews.llvm.org/D117142) was to fix exactly the reported case.

However, I'd argue that a slight modification to the example is an unintended regression. If macros hide the "class" token, the scope is not correctly detected.

#define MY_THING(name) class name##Thing final
MY_THING(Foo)
{
    int func() { return 7; }
}

is formatted to:

#define MY_THING(name) class name##Thing final
MY_THING(Foo)
{
    int func()
    {
        return 7;
    }
}
@llvmbot
Copy link
Member

llvmbot commented Mar 26, 2025

@llvm/issue-subscribers-clang-format

Author: Rafael Stahl (rafzi)

I stumbled upon https://github.com//issues/60627 which describes this same issue. Over there, the conclusion seems to be wont-fix because the intention of the related change (https://reviews.llvm.org/D117142) was to fix exactly the reported case.

However, I'd argue that a slight modification to the example is an unintended regression. If macros hide the "class" token, the scope is not correctly detected.

#define MY_THING(name) class name##Thing final
MY_THING(Foo)
{
    int func() { return 7; }
}

is formatted to:

#define MY_THING(name) class name##Thing final
MY_THING(Foo)
{
    int func()
    {
        return 7;
    }
}

@owenca
Copy link
Contributor

owenca commented Apr 3, 2025

clang-format needs to know what the macro is about:

$ cat a.cc
MY_THING(Foo) {
  int func() { return 7; }
}
$ cat .clang-format
AllowShortFunctionsOnASingleLine: Inline
Macros: [MY_THING(a)=class a]
$ clang-format -version
clang-format version 20.1.1
$ clang-format a.cc | diff a.cc -
$ 

@owenca owenca closed this as completed Apr 3, 2025
@EugeneZelenko EugeneZelenko added the question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! label Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-format question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Projects
None yet
Development

No branches or pull requests

4 participants