summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-07-11 14:33:06 +0000
committerDaniel Jasper <djasper@google.com>2013-07-11 14:33:06 +0000
commita3501d4b81c170d3b0fc7645a6f5357c24e517e7 (patch)
treee6276d2d47ae17385a1f805678ecbd63a9db480d
parent889865fb699aa9d9cfd50d97239fd3fcf21f2f30 (diff)
downloadbcm5719-llvm-a3501d4b81c170d3b0fc7645a6f5357c24e517e7.tar.gz
bcm5719-llvm-a3501d4b81c170d3b0fc7645a6f5357c24e517e7.zip
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
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp3
-rw-r--r--clang/unittests/Format/FormatTest.cpp3
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) {
OpenPOWER on IntegriCloud