]> granicus.if.org Git - clang/commitdiff
[clang-format] [PR42417] clang-format inserts a space after '->' for operator->(...
authorPaul Hoad <mydeveloperday@gmail.com>
Fri, 4 Oct 2019 13:24:15 +0000 (13:24 +0000)
committerPaul Hoad <mydeveloperday@gmail.com>
Fri, 4 Oct 2019 13:24:15 +0000 (13:24 +0000)
Summary:
https://bugs.llvm.org/show_bug.cgi?id=42417

This revision removes the extra space between the opertor-> and the parens ()

```
class Bug {
    auto operator-> () -> int*;
    auto operator++(int) -> int;
};
```

Reviewers: klimek, owenpan, byoungyoung, mitchell-stellar

Reviewed By: mitchell-stellar

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D68242

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373746 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index e6dfffd9733449476519f82387482f3ba23110a4..50e3d056b8385187aacb8aceb85cec7a3d1fe2a4 100644 (file)
@@ -1393,7 +1393,9 @@ private:
                Style.Language == FormatStyle::LK_Java) {
       Current.Type = TT_LambdaArrow;
     } else if (Current.is(tok::arrow) && AutoFound && Line.MustBeDeclaration &&
-               Current.NestingLevel == 0) {
+               Current.NestingLevel == 0 &&
+               !Current.Previous->is(tok::kw_operator)) {
+      // not auto operator->() -> xxx;
       Current.Type = TT_TrailingReturnArrow;
       TrailingReturnFound = true;
     } else if (Current.is(tok::star) ||
index e982c8b2ab07e6ec540bded589ff74a1f97d803d..b770d0f26f8378df5836ff2da1c9aaa8b46effd7 100644 (file)
@@ -4956,6 +4956,10 @@ TEST_F(FormatTest, DontBreakBeforeQualifiedOperator) {
 
 TEST_F(FormatTest, TrailingReturnType) {
   verifyFormat("auto foo() -> int;\n");
+  // correct trailing return type spacing
+  verifyFormat("auto operator->() -> int;\n");
+  verifyFormat("auto operator++(int) -> int;\n");
+
   verifyFormat("struct S {\n"
                "  auto bar() const -> int;\n"
                "};");