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] Unstable output with AllowShortFunctionsOnASingleLine=inline #102937

Closed
vient opened this issue Aug 12, 2024 · 1 comment · Fixed by #102998
Closed

[clang-format] Unstable output with AllowShortFunctionsOnASingleLine=inline #102937

vient opened this issue Aug 12, 2024 · 1 comment · Fixed by #102998

Comments

@vient
Copy link
Member

vient commented Aug 12, 2024

Somewhat minified test case:

void f() {
#define M(x)     \
  case 0: {      \
    return {#x}; \
  }
}

Formatting it with clang-format-18 -Werror --style='{AllowShortFunctionsOnASingleLine: Inline}' results in oscillating outputs - original code produces output 1, it produces output 2, which produces output 1, and so on (1️⃣🔄2️⃣).
Output 1:

void f() {
#define M(x)                                                                   \
  case 0: {                                                                    \
    return {                                                                   \
      #x                                                                       \
    };                                                                         \
  }
}

Output 2:

void f() {
#define M(x)                                                                   \
  case 0: {                                                                    \
    return {#x};                                                               \
  }
}

It is a regression in clang-format-18, 17 works fine. Issue is still present in clang-format-19, did not check with trunk.

@vient
Copy link
Member Author

vient commented Aug 12, 2024

This test does not produce oscillating behavior but still takes two runs to converge

void f() {
#define M(x)     \
    return {#x}; 
}

becomes

void f() {
#define M(x)                                                                   \
  return {                                                                     \
    #x                                                                         \
  };
}

which then becomes

void f() {
#define M(x) return {#x};
}

Macro parameter (x) can be removed but {#x} part seems to be crucial - removing # makes the issue go away in both this and original test.

@owenca owenca self-assigned this Aug 13, 2024
owenca added a commit to owenca/llvm-project that referenced this issue Aug 13, 2024
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Aug 13, 2024
tru pushed a commit to llvmbot/llvm-project that referenced this issue Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants