Skip to content

[clang-format] Bug when formatting a macro #76991

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

Closed
prj- opened this issue Jan 4, 2024 · 6 comments · Fixed by #78921
Closed

[clang-format] Bug when formatting a macro #76991

prj- opened this issue Jan 4, 2024 · 6 comments · Fixed by #78921
Assignees
Labels
clang-format invalid-code-generation Tool (e.g. clang-format) produced invalid code that no longer compiles

Comments

@prj-
Copy link

prj- commented Jan 4, 2024

$  clang-format --version
clang-format version 17.0.6
$ cat simple.cpp
#ifndef PLEXFE_QFUNCTION
  #define PLEXFE_QFUNCTION(fname, f0_name, f1_name) \
    CEED_QFUNCTION(PlexQFunction##fname)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) \
    { \
        const CeedScalar invJ[2][2]    = { \
          {qdata[i+Q*3], qdata[i+Q*5]}, \
          {qdata[i+Q*4], qdata[i+Q*6]} \
        }; \
      return CEED_ERROR_SUCCESS; \
    }
#endif

PLEXFE_QFUNCTION(A, B, C)
$ clang-format --style=file:clang-format.txt simple.cpp 
#ifndef PLEXFE_QFUNCTION
  #define PLEXFE_QFUNCTION(fname, f0_name, f1_name) \
    CEED_QFUNCTION(PlexQFunction##fname)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) \
    { \
      const CeedScalar invJ[2][2] = { \
        {qdata[i + Q * 3], qdata[i + Q * 5]},
        {qdata[i + Q * 4], qdata[i + Q * 6]}
      }; \
      return CEED_ERROR_SUCCESS; \
    }
#endif

PLEXFE_QFUNCTION(A, B, C)

Also triggered by Debian clang-format version 18.0.0 (++20240102111311+9b7cf5bfb08b-1~exp1~20240102111413.1794).
clang-format.txt

@owenca owenca added the invalid-code-generation Tool (e.g. clang-format) produced invalid code that no longer compiles label Jan 6, 2024
@prj-
Copy link
Author

prj- commented Jan 12, 2024

Is there something I could do to help get this bug fixed?

@prj-
Copy link
Author

prj- commented Jan 21, 2024

@owenca, any update on this?

@owenca owenca self-assigned this Jan 22, 2024
@owenca
Copy link
Contributor

owenca commented Jan 22, 2024

Is there something I could do to help get this bug fixed?

A minimum reproducer would help. :)

@owenca
Copy link
Contributor

owenca commented Jan 22, 2024

Here's one:

$ cat test.cpp
#define FOO \
  int foo[][2] = { \
    {0, 1} \
  };
$ clang-format -version
clang-format version 17.0.6
$ clang-format -style='{AlignArrayOfStructures: Left, AlignEscapedNewlines: DontAlign}' test.cpp
#define FOO \
  int foo[][2] = { \
      {0, 1}
  };
$ 

@prj-
Copy link
Author

prj- commented Jan 22, 2024

Thank you very much.

@frank101010
Copy link

frank101010 commented Feb 22, 2024

I've found out that this bug can be worked around by adding a trailing comma to the last element in the list, i.e. formatting

#define FOO \
  int foo[][2] = { \
      {0, 1}, \
  };

should work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-format invalid-code-generation Tool (e.g. clang-format) produced invalid code that no longer compiles
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants