r207961 - clang-format: Improve understanding of decltype.

Daniel Jasper djasper at google.com
Mon May 5 05:36:30 PDT 2014


Author: djasper
Date: Mon May  5 07:36:29 2014
New Revision: 207961

URL: http://llvm.org/viewvc/llvm-project?rev=207961&view=rev
Log:
clang-format: Improve understanding of decltype.

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

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

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=207961&r1=207960&r2=207961&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon May  5 07:36:29 2014
@@ -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 &&

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=207961&r1=207960&r2=207961&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon May  5 07:36:29 2014
@@ -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");





More information about the cfe-commits mailing list