Skip to content

Nested scopes regression in clang-format 13.0.0, worked in clang-format 12.0.1 #52911

Closed
@JohnC32

Description

Nested scopes do not work in 13.0.0. Below we use scopes to increase indentation to group like items, a common pattern in writing checks. Here I've simplified things a bit.

Using clang-format 12.0.1, on testcheck.cpp we have:

int foo() {
    // first check
    {
        int a = 1;
        CHECK(a == 1);
    }

    // extra scope to group common types of checks
    {
        {
            char a = 'a';
            CHECK(a == 'a');
        }

        {
            char b = 'b';
            CHECK(b == 'b');
        }
    }

    // other checks
    {
        bool b = false;
        CHECK(b == false);
    }
}

If I then run clang-format 13.0.0 on testcheck.cpp we get:

// clang-format 13.0.0 result
int foo() {
    // first check
    {
        int a = 1;
        CHECK(a == 1);
    }

    // extra scope to group common types of checks
    {{char a = 'a';
    CHECK(a == 'a');
}

{
    char b = 'b';
    CHECK(b == 'b');
}
}

// other checks
{
    bool b = false;
    CHECK(b == false);
}
}

Here's the _clang-format used in the above.

---
BasedOnStyle: Google
IndentWidth: 4
...

Note, if one puts statements in the extra scope, then clang-format 13 is okay. For example, if we add an unused variable, clang-format 13 is good:

    // extra scope to group common types of checks
    {
        int makeClangFormat13Happy;
        {

This maybe related to issue #42582, but for my case all is good with clang-format 12.0.1 and we have issues with 13.0.0. Since this is a regression, I thought it may help to create a separate issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorclang-formatregression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions