-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang-format]: Add StaticInlineOnly and StaticInline options to ShortFunctionStyle
#133598
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15120,6 +15120,135 @@ TEST_F(FormatTest, PullInlineFunctionDefinitionsIntoSingleLine) { | |
| MergeInlineOnly); | ||
| } | ||
|
|
||
| TEST_F(FormatTest, PullStaticInlineFunctionDefinitionsIntoSingleLine) { | ||
| FormatStyle MergeStaticInlineOnly = getLLVMStyle(); | ||
| MergeStaticInlineOnly.AllowShortFunctionsOnASingleLine = | ||
| FormatStyle::SFS_StaticInlineOnly; | ||
| verifyFormat("static inline int f() { return 42; }", | ||
| "static inline int f() {\n" | ||
| " return 42; \n" | ||
| "}", | ||
| MergeStaticInlineOnly); | ||
| verifyFormat("inline static int f() { return 42; }", | ||
| "inline static int f() \n" | ||
| "{\n" | ||
| " return 42; \n" | ||
| "}", | ||
| MergeStaticInlineOnly); | ||
| verifyNoChange("int f() {\n" | ||
| " return 42;\n" | ||
| "}", | ||
| MergeStaticInlineOnly); | ||
|
|
||
| verifyFormat("void f1(void) {\n" | ||
| "}", | ||
| "void f1(void)\n" | ||
| "{\n" | ||
| "}", | ||
| MergeStaticInlineOnly); | ||
|
|
||
| verifyNoChange("int f2(int a, int b) {\n" | ||
| " return a + b;\n" | ||
| "}", | ||
| MergeStaticInlineOnly); | ||
|
|
||
| verifyNoChange("static void f3(void) {\n" | ||
| "}\n", | ||
| MergeStaticInlineOnly); | ||
|
|
||
| verifyFormat("static int f4(int a, int b) {\n" | ||
| " return a + b;\n" | ||
| "}\n", | ||
| MergeStaticInlineOnly); | ||
|
|
||
| verifyNoChange("static inline void f5(void) {}", MergeStaticInlineOnly); | ||
|
|
||
| verifyFormat("static inline int f6(int a, int b) { return a + b; }", | ||
| "static inline int f6(int a, int b) \n" | ||
| "{ return a + b; }", | ||
| MergeStaticInlineOnly); | ||
|
|
||
| verifyFormat("int f(int a, int b) {\n" | ||
| " return a + b;\n" | ||
| "}", | ||
| "int f(int a, int b) { return a + b; }", MergeStaticInlineOnly); | ||
|
|
||
| FormatStyle MergeStaticInline = getLLVMStyle(); | ||
| MergeStaticInline.AllowShortFunctionsOnASingleLine = | ||
| FormatStyle::SFS_StaticInline; | ||
| verifyFormat("static inline int f() { return 42; }", | ||
| "static inline int f() {\n" | ||
| " return 42; \n" | ||
| "}", | ||
| MergeStaticInline); | ||
| verifyFormat("inline static int f() { return 42; }", | ||
| "inline static int f() \n" | ||
| "{\n" | ||
| " return 42; \n" | ||
| "}", | ||
| MergeStaticInline); | ||
| verifyNoChange("int f() {\n" | ||
| " return 42;\n" | ||
| "}", | ||
| MergeStaticInline); | ||
|
|
||
| verifyFormat("void f1(void) {}", | ||
| "void f1(void)\n" | ||
| "{\n" | ||
| "}", | ||
| MergeStaticInline); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add some tests with attributes.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added some tests with different attributes in different places. If you have any idea what should be added - small example (just code line) would be appreciated.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no preference regarding constexpr because it was not mentioned in 'Inline' or 'InlineOnly' options before. Right now it won't be formatted if StaticInline is specified (I added unit test to show this). Please let me know if I need to change this. |
||
| // additional attribute tests | ||
| verifyFormat("inline static __attribute__((unused)) int f() { return 42; }", | ||
| "inline static __attribute__((unused)) int f() \n" | ||
| "{\n" | ||
| " return 42; \n" | ||
| "}", | ||
| MergeStaticInline); | ||
| verifyFormat("__attribute__((unused)) inline static int f() { return 42; }", | ||
| "__attribute__((unused)) inline static int f() \n" | ||
| "{\n" | ||
| " return 42; \n" | ||
| "}", | ||
| MergeStaticInline); | ||
| verifyFormat("inline static int f() __attribute__((unused)) { return 42; }", | ||
| "inline static int f() \n" | ||
| "__attribute__((unused)) \n" | ||
| "{\n" | ||
| " return 42; \n" | ||
| "}", | ||
| MergeStaticInline); | ||
| verifyFormat("__attribute__((unused)) inline static int f() { return 42; }", | ||
| "__attribute__((unused)) inline static int f() \n" | ||
| "{\n" | ||
| " return 42; \n" | ||
| "}", | ||
| MergeStaticInline); | ||
|
|
||
| verifyFormat("inline static const int f() { return 42; }", | ||
| "inline static const int f() \n" | ||
| "{\n" | ||
| " return 42; \n" | ||
| "}", | ||
| MergeStaticInline); | ||
|
|
||
| verifyFormat("_Noreturn static inline auto f() { return 42; }", | ||
| "_Noreturn static inline auto f() \n" | ||
| "{\n" | ||
| " return 42; \n" | ||
| "}", | ||
| MergeStaticInline); | ||
|
|
||
| verifyFormat("constexpr auto f() {\n" | ||
| " return 42;\n" | ||
| "}", | ||
| "constexpr auto f() \n" | ||
| "{\n" | ||
| " return 42; \n" | ||
| "}", | ||
| MergeStaticInline); | ||
| } | ||
|
|
||
| TEST_F(FormatTest, PullInlineOnlyFunctionDefinitionsIntoSingleLine) { | ||
| FormatStyle MergeInlineOnly = getLLVMStyle(); | ||
| MergeInlineOnly.AllowShortFunctionsOnASingleLine = | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this check into the
ifs of the loop, exit early.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added additional check in while(). Please take a look.