r220373 - clang-format: Fix incorrect trailing return arrow detection.

Daniel Jasper djasper at google.com
Wed Oct 22 01:42:59 PDT 2014


Author: djasper
Date: Wed Oct 22 03:42:58 2014
New Revision: 220373

URL: http://llvm.org/viewvc/llvm-project?rev=220373&view=rev
Log:
clang-format: Fix incorrect trailing return arrow detection.

Before:
  auto doSomething(Aaaaaa* aaaaaa) -> decltype(aaaaaa -> f()) {}

After:
  auto doSomething(Aaaaaa* aaaaaa) -> decltype(aaaaaa->f()) {}

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=220373&r1=220372&r2=220373&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Oct 22 03:42:58 2014
@@ -779,7 +779,7 @@ private:
       } else if (Current.is(tok::kw_auto)) {
         AutoFound = true;
       } else if (Current.is(tok::arrow) && AutoFound &&
-                 Line.MustBeDeclaration) {
+                 Line.MustBeDeclaration && Current.NestingLevel == 0) {
         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=220373&r1=220372&r2=220373&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Oct 22 03:42:58 2014
@@ -3526,6 +3526,7 @@ TEST_F(FormatTest, TrailingReturnType) {
                "    -> alias::tensor<Order, T, mem::tag::cpu> {}");
   verifyFormat("auto SomeFunction(A aaaaaaaaaaaaaaaaaaaaa) const\n"
                "    -> decltype(f(aaaaaaaaaaaaaaaaaaaaa)) {}");
+  verifyFormat("auto doSomething(Aaaaaa* aaaaaa) -> decltype(aaaaaa->f()) {}");
 
   // Not trailing return types.
   verifyFormat("void f() { auto a = b->c(); }");





More information about the cfe-commits mailing list