From 936a67f089efd31354cf1f1f3b864b81fb5aad0e Mon Sep 17 00:00:00 2001 From: mydeveloperday Date: Fri, 17 Dec 2021 18:33:17 +0000 Subject: [PATCH] [clang-format] Extra spaces surrounding arrow in templated member call in variable decl https://github.com/llvm/llvm-project/issues/43196 Fixes #43196 -> is incorrectly interpreted as a TrailingReturnArrow if we've seen an auto ``` auto p = new A; auto x = p -> foo<1>(); ``` Reviewed By: curdeius Differential Revision: https://reviews.llvm.org/D115903 --- clang/lib/Format/TokenAnnotator.cpp | 2 +- clang/unittests/Format/FormatTest.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 6fc3a4d..5809e4c 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1679,7 +1679,7 @@ private: Current.setType(TT_LambdaArrow); } else if (Current.is(tok::arrow) && AutoFound && Line.MustBeDeclaration && Current.NestingLevel == 0 && - !Current.Previous->is(tok::kw_operator)) { + !Current.Previous->isOneOf(tok::kw_operator, tok::identifier)) { // not auto operator->() -> xxx; Current.setType(TT_TrailingReturnArrow); } else if (Current.is(tok::arrow) && Current.Previous && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 2b9a72e..c2a5fbb 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -6780,6 +6780,9 @@ TEST_F(FormatTest, TrailingReturnType) { // Not trailing return types. verifyFormat("void f() { auto a = b->c(); }"); + verifyFormat("auto a = p->foo();"); + verifyFormat("int a = p->foo();"); + verifyFormat("auto lmbd = [] NOEXCEPT -> int { return 0; };"); } TEST_F(FormatTest, DeductionGuides) { -- 2.7.4