Skip to content

[clang-format] Macro replacement results in long code to be put on a single line. #148199

Open
@JVApen

Description

@JVApen
#define DEFAULT_UNREACHABLE() default: break
auto func()
{
    switch (0)
    {
        case 0:
         return MyVeryLongInitialization{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z, {MyOtherClass{abc,def,ghi}}};   
        case 1:
         return MyVeryLongInitialization{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z, {MyOtherClass{abc,def,ghi}}};   
         DEFAULT_UNREACHABLE();
    }
}

I'm using the following config:

--style="{ 'Macros': ['DEFAULT_UNREACHABLE=default: break' ], 'ColumnLimit': 20, 'AllowShortCaseExpressionOnASingleLine': true}"

results in

#define DEFAULT_UNREACHABLE() \
  default:                    \
    break
auto func() {
  switch (0) {
  case 0:
    return MyVeryLongInitialization{
        a,
        b,
        c,
        d,
        e,
        f,
        g,
        h,
        i,
        j,
        k,
        l,
        m,
        n,
        o,
        p,
        q,
        r,
        s,
        t,
        u,
        v,
        w,
        x,
        y,
        z,
        {MyOtherClass{
            abc,
            def,
            ghi}}};
  case 1:
    return MyVeryLongInitialization{a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, {MyOtherClass{abc, def, ghi}}};
  DEFAULT_UNREACHABLE();
  }
}

while I expect the second return to be formatted the same as the first one.

Note that with 'Macros', I cannot define a replacement for DEFAULT_UNREACHABLE(), only for DEFAULT_UNREACHABLE

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions