[PATCH] D68242: [clang-format] [PR42417] clang-format inserts a space after '->' for operator->() overloading

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 30 13:29:21 PDT 2019


MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: klimek, owenpan, byoungyoung.
MyDeveloperDay added a project: clang-format.
Herald added a project: clang.

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;

};


Repository:
  rC Clang

https://reviews.llvm.org/D68242

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4830,6 +4830,10 @@
 
 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"
                "};");
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1387,7 +1387,9 @@
                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) ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68242.222487.patch
Type: text/x-patch
Size: 1251 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190930/405531cc/attachment.bin>


More information about the cfe-commits mailing list