<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57724>57724</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-format does not remove space before "::" in C++
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dbaron
</td>
</tr>
</table>
<pre>
I found (during a code review) that clang-format does not remove the space prior to "::" in "Class::member" syntax in C++.
(This surprised me because I had to make a code formatting comment during a Chromium code review, whereas I normally expect the auto-formatting that happens during Chromium development to take care of all formatting issues.)
A simple test case is the following C++ file:
```cpp
class C {
public:
void Method();
};
void C :: Method() {}
int main() {
C c;
c . Method();
C* cp = &c;
c -> Method();
return 0;
}
```
If I run `clang-format` on this file, it produces the output:
```cpp
class C {
public:
void Method();
};
void C ::Method() {}
int main() {
C c;
c.Method();
C* cp = &c;
c->Method();
return 0;
}
```
For clarity, a diff of the input and output is the following:
```diff
--- test-in.cc 2022-09-13 16:17:10.014555637 -0400
+++ test-out.cc 2022-09-13 16:17:26.278729118 -0400
@@ -1,16 +1,16 @@
class C {
public:
void Method();
};
-void C :: Method() {}
+void C ::Method() {}
int main() {
C c;
- c . Method();
+ c.Method();
C* cp = &c;
- c -> Method();
+ c->Method();
return 0;
}
```
Note that I was expecting six spaces to be removed, but only five of those spaces were actually removed. I would expect the space before the `::` to also be removed.
I've tested this on two different distro-packaged versions of `clang-format`, one of which is 14.0.0-1ubuntu1 from Ubuntu 22.04.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFVs2OozgQfhpyKYHAJBAOHLrTO1IOu6fdBzCmCN4BjPyTdL_9lk3SnWyUzGg10koIMJTr96v63Kj2o95Dp9zUQsS2rdNyOgAHoVoEjUeJp4hVYHtuQQx8OsSd0iMtWoUGJmVJaFRHJAkEM3OBMGupNFhF-liUv_iLMZCTX-8GbszyccSxQe1_mY_J8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