Skip to content

Formatter's WhitespaceManager does not measure unicode column width #37705

@vit9696

Description

@vit9696
Bugzilla Link 38357
Version trunk
OS All

Extended Description

AlignConsecutiveDeclarations in formatter (and possibly several other options depending on WhiteSpaceFormatter) fail to format the following example properly.

Language:        Cpp
BasedOnStyle:    LLVM
ColumnLimit:     100
AlignConsecutiveDeclarations: true
typedef struct {
  int *a; // ААААААААААААААААААААААААААААААААААААААААААААА
  unsigned char *b; // ААААААААААААААААААААААААААААААААААААААААААААА
  char c; // ААААААААААААААААААААААААААААААААААААААААААААА
  unsigned long long d; //
  long double        e; //
} s;

The expected output is as follows:

typedef struct {
  int *              a; // ААААААААААААААААААААААААААААААААААААААААААААА
  unsigned char *    b; // ААААААААААААААААААААААААААААААААААААААААААААА
  char               c; // ААААААААААААААААААААААААААААААААААААААААААААА
  unsigned long long d; //
  long double        e; //
} s;

Yet the resulting output is exactly the same as the input above. Formatter works fine when latin-only characters are used.

typedef struct {
  int *              a; // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  unsigned char *    b; // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  char               c; // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  unsigned long long d; //
  long double        e; //
} s;

It seems that WhitespaceManager::Change relies on TokenLength (which is the length in bytes) and is not aware of the actual column width obtained by e.g. encoding::columnWidth.

The issue is present at least in 6.0 and onwards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorbugzillaIssues migrated from bugzillaclang-formatconfirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions