]> granicus.if.org Git - clang/commitdiff
clang-format: Detect weird macro lambda usage.
authorDaniel Jasper <djasper@google.com>
Tue, 11 Mar 2014 09:29:46 +0000 (09:29 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 11 Mar 2014 09:29:46 +0000 (09:29 +0000)
Before:
  void f() {
    MACRO((const AA & a) { return 1; });
  }

After:
  void f() {
    MACRO((const AA &a) { return 1; });
  }

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

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

index bb91fa7f52c87fcc9ef652ffec9eb9022bd71c9d..34aef99a7b296a55ea99530d4b3a14c1dca4a0f1 100644 (file)
@@ -183,6 +183,9 @@ private:
           !CurrentToken->Next->HasUnescapedNewline &&
           !CurrentToken->Next->isTrailingComment())
         HasMultipleParametersOnALine = true;
+      if (CurrentToken->is(tok::kw_const) ||
+          CurrentToken->isSimpleTypeSpecifier())
+        Contexts.back().IsExpression = false;
       if (!consumeToken())
         return false;
       if (CurrentToken && CurrentToken->HasUnescapedNewline)
@@ -731,7 +734,8 @@ private:
             LeftOfParens &&
             LeftOfParens->isOneOf(tok::kw_sizeof, tok::kw_alignof);
         if (ParensAreType && !ParensCouldEndDecl && !IsSizeOfOrAlignOf &&
-            (Contexts.back().IsExpression ||
+            ((Contexts.size() > 1 &&
+              Contexts[Contexts.size() - 2].IsExpression) ||
              (Current.Next && Current.Next->isBinaryOperator())))
           IsCast = true;
         if (Current.Next && Current.Next->isNot(tok::string_literal) &&
index 6e8e955dda57dbdb94d9ecb6db42e7270ab1eae6..d3ad9fb5d3b58a6a48ab426018ab0d39bcdc88b3 100644 (file)
@@ -7986,6 +7986,11 @@ TEST_F(FormatTest, FormatsLambdas) {
                "  bar([]() {} // Did not respect SpacesBeforeTrailingComments\n"
                "      );\n"
                "}");
+
+  // Lambdas created through weird macros.
+  verifyFormat("void f() {\n"
+               "  MACRO((const AA &a) { return 1; });\n"
+               "}");
 }
 
 TEST_F(FormatTest, FormatsBlocks) {