<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/74876>74876</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Extra space is sometimes placed before the C++ '&' operator, regression in clang-format 17
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-format
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          JohnC32
      </td>
    </tr>
</table>

<pre>
    With clang-format 17 an extra space is sometimes placed before the C++ '&' operator. This appears to
be a regression from clang-format 16.

Given the following C++ code, it is indented correctly using clang-format 16:

```c++
class Goo {
   public:
    int a;
};

class Foo {
   public:
    Foo(Goo& aGoo) : mGoo(aGoo) {}

    bool operator<(const Foo& other) const { return true; }

 protected:
    Goo& mGoo;
};
```

using `_clang-format`:

```yaml
---
BasedOnStyle: Google
IndentWidth: 4
ColumnLimit: 100
...
```

clang-format 17 yields the following:

```c++
class Goo {
   public:
    int a;
};

class Foo {
   public:
    Foo(Goo& aGoo) : mGoo(aGoo) {}

    bool operator<(const Foo& other) const { return true; }

 protected:
    Goo & mGoo;
};
```

Notice there is extra space put before the '&' reference operator in the "Goo& mGoo" data member by
clang-format 17 (it is correct with clang-format 16).

As a side note, I do see that clang-format 17 behaves better than clang-format 16 when '&' is a
non-reference operator, e.g. code using boost::serialization,
https://www.boost.org/doc/libs/1_79_0/libs/serialization/doc/tutorial.html, where a space should be
before the '&', so that's an improvement with clang-format 17.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVU-PuzYQ_TTOZRQEJgvkwCHJNqtfVbWHVtrjytiT4Mp4kG2Spp--MmSzJLttVbXHShGQYfzmzxveCO_10SLW7GnLnp4XYggtufp7au0u54uG1KV-1aEFaYQ9Lg_kOhEgK0FYwN-CE-B7IRG0B08dBt2hh94IiQoaPJBDCC3CjvEt41tgvGS8YLwE6tGJQC6BX1rtQ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