]> granicus.if.org Git - clang/commitdiff
clang-format: Improve understanding of decltype.
authorDaniel Jasper <djasper@google.com>
Mon, 5 May 2014 12:36:29 +0000 (12:36 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 5 May 2014 12:36:29 +0000 (12:36 +0000)
Before:
  SomeFunction([](decltype(x), A * a) {});

After:
  SomeFunction([](decltype(x), A *a) {});

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207961 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 843d8777188cdc798cc67307b3caeeb315d909bb..65c0cabffc110a95c5babe2bf7380914b3ee7857 100644 (file)
@@ -692,7 +692,8 @@ private:
     } else if (Current.isOneOf(tok::kw_return, tok::kw_throw)) {
       Contexts.back().IsExpression = true;
     } else if (Current.is(tok::l_paren) && !Line.MustBeDeclaration &&
-               !Line.InPPDirective) {
+               !Line.InPPDirective && Current.Previous &&
+               Current.Previous->isNot(tok::kw_decltype)) {
       bool ParametersOfFunctionType =
           Current.Previous && Current.Previous->is(tok::r_paren) &&
           Current.Previous->MatchingParen &&
index 1380dd85a48af1717000624f55f2ad8b79e0aa6b..7db87cb3ce54f510a18caaf7273e4b7809f87ed1 100644 (file)
@@ -8432,6 +8432,9 @@ TEST_F(FormatTest, FormatsLambdas) {
   verifyFormat("SomeFunction([]() { // A cool function...\n"
                "  return 43;\n"
                "});");
+  verifyFormat("void f() {\n"
+               "  SomeFunction([](decltype(x), A *a) {});\n"
+               "}");
 
   // Lambdas with return types.
   verifyFormat("int c = []() -> int { return 2; }();\n");