Skip to content

clang-format-18 ColumnLimit: 0 breaks formatting when encountering empty #if 0 ... #endif section #68404

@MartinsSmirnovs

Description

@MartinsSmirnovs

Given following .clang-format file:

ColumnLimit: 0

And following foo.cpp source file:

struct Foo {
  Foo() : a(2) {
#if 0
    // comment
#endif
  }

  Foo &operator+=(const Foo &) {
    return *this;
  }

  int a = 0;
};

I expect that clang-format-18 foo.cpp will not perform formatting (or at least not in a broken way), however, it does:

$ clang-format-18 foo.cpp 
struct Foo {
  Foo() : a(2){
#if 0
    // comment
#endif
          }

          Foo
          & operator+=(const Foo &) {
    return *this;
  }

  int a = 0;
};

After changing the value of ColumnLimit: 0 to something like 80, the issue is no more. We can also add some code into the #if 0 part, and clang-format will not perform formatting in broken way anymore with ColumnLimit: 0.
clang-format-18 version:

$ clang-format-18 --version
Ubuntu clang-format version 18.0.0 (++20230929042255+ab472cd4ea12-1~exp1~20230929042400.1214)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions