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(); }

llvm-svn: 186087
This commit is contained in:
Daniel Jasper 2013-07-11 14:33:06 +00:00
parent 889865fb69
commit a3501d4b81
2 changed files with 5 additions and 1 deletions

View File

@ -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 =

View File

@ -2476,6 +2476,9 @@ TEST_F(FormatTest, TrailingReturnType) {
verifyFormat("template <size_t Order, typename T>\n"
"auto load_img(const std::string &filename)\n"
" -> alias::tensor<Order, T, mem::tag::cpu> {}");
// Not trailing return types.
verifyFormat("void f() { auto a = b->c(); }");
}
TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {