Skip to content

clang-format: AlignConsecutiveBitFields doesn't work with bit field length specified by template argument #145391

Closed as duplicate of#142050
@mathcounts4

Description

@mathcounts4

clang-format version 19.1.7

_clang-format:

BasedOnStyle: LLVM
AlignConsecutiveBitFields: AcrossEmptyLinesAndComments

myfile.hpp:

template <int Bits>
struct ABC {
    std::size_t fAName : Bits;
    std::size_t fB : 1;
    std::size_t fCOtherName   : 63 - Bits;
};

Output:

>clang-format myfile.hpp
template <int Bits> struct ABC {
  std::size_t fAName : Bits;
  std::size_t fB          : 1;
  std::size_t fCOtherName : 63 - Bits;
};

In the output, the : and Bits on fAName are not vertically aligned with the : and bit field lengths on fB and fCOtherName.

Workaround: change fAName : Bits; to fAName : 0 + Bits;, which clang-format then aligns properly.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions