From: Daniel Jasper Date: Thu, 11 Jul 2013 14:33:06 +0000 (+0000) Subject: Improve detection of trailing return types. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3262f4c10520cf11acea4cf590cfbf055924a41e;p=clang Improve detection of trailing return types. Trailing return types can only occur in declaration contexts. Before: void f() { auto a = b -> c(); } After: void f() { auto a = b->c(); } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186087 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 1e4de6eb94..14206445fa 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -607,7 +607,8 @@ private: NameFound = true; } else if (Current.is(tok::kw_auto)) { AutoFound = true; - } else if (Current.is(tok::arrow) && AutoFound) { + } else if (Current.is(tok::arrow) && AutoFound && + Line.MustBeDeclaration) { Current.Type = TT_TrailingReturnArrow; } else if (Current.isOneOf(tok::star, tok::amp, tok::ampamp)) { Current.Type = diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 42cd89cc8b..37ac1a264a 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2476,6 +2476,9 @@ TEST_F(FormatTest, TrailingReturnType) { verifyFormat("template \n" "auto load_img(const std::string &filename)\n" " -> alias::tensor {}"); + + // Not trailing return types. + verifyFormat("void f() { auto a = b->c(); }"); } TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {