diff options
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 3 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 3 |
2 files changed, 5 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 1e4de6eb943..14206445fac 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 42cd89cc8b7..37ac1a264a3 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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) { |

