r186087 - Improve detection of trailing return types.
Daniel Jasper
djasper at google.com
Thu Jul 11 07:33:06 PDT 2013
Author: djasper
Date: Thu Jul 11 09:33:06 2013
New Revision: 186087
URL: http://llvm.org/viewvc/llvm-project?rev=186087&view=rev
Log:
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(); }
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=186087&r1=186086&r2=186087&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Jul 11 09:33:06 2013
@@ -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 =
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=186087&r1=186086&r2=186087&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Jul 11 09:33:06 2013
@@ -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) {
More information about the cfe-commits
mailing list