Issue 71825
Summary clang-format-18 `AlignTrailingComments: Kind: Leave` moves comments #4
Labels clang-format
Assignees
Reporter MartinsSmirnovs
    Given following `.clang-format` file:
```
AlignArrayOfStructures: Left
AlignTrailingComments:
    Kind: Leave
IndentWidth: 4
```
And following `foo.cpp` source file:
```
#include <string>
#include <vector>

struct Foo {
    std::string text;
    int number;
};

const std::vector<Foo> table1 = {
 // This is a comment
    // The purpose of comments is to describe what and why is going on in code
    // Specifically this comment here is for the demonstration of clang-format's
    // bug
    {"Hello", 1},
 {"There", 2},
    {"!",     3},
};
```
I expect that `clang-format foo.cpp` will not move comments, however, it does:
```
$ clang-format foo.cpp 
#include <string>
#include <vector>

struct Foo {
    std::string text;
    int number;
};

const std::vector<Foo> table1 = {
  // This is a comment
  // The purpose of comments is to describe what and why is going on in code
  // Specifically this comment here is for the demonstration of clang-format's
  // bug
 {"Hello", 1},
    {"There", 2},
    {"!", 3},
};
```
Looks like the comments get moved to the default `IndentWidth` of `2`.

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


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to