summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Hoad <mydeveloperday@gmail.com>2019-10-04 13:24:15 +0000
committerPaul Hoad <mydeveloperday@gmail.com>2019-10-04 13:24:15 +0000
commita37a6dcd04b0c0a0f9eea93ba0a5070a5421a29a (patch)
treee7eccc788226f1f16f210a3569b081fecd1cc5d3
parent434d59250e3822a141fb5070ae0432f31da77734 (diff)
downloadbcm5719-llvm-a37a6dcd04b0c0a0f9eea93ba0a5070a5421a29a.tar.gz
bcm5719-llvm-a37a6dcd04b0c0a0f9eea93ba0a5070a5421a29a.zip
[clang-format] [PR42417] clang-format inserts a space after '->' for operator->() overloading
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 llvm-svn: 373746
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp4
-rw-r--r--clang/unittests/Format/FormatTest.cpp4
2 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index e6dfffd9733..50e3d056b83 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -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) ||
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index e982c8b2ab0..b770d0f26f8 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -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"
"};");
OpenPOWER on IntegriCloud