Skip to content

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

Closed
@prj-

Description

@prj-
$  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

Metadata

Metadata

Assignees

Labels

clang-formatinvalid-code-generationTool (e.g. clang-format) produced invalid code that no longer compiles

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions