diff options
| author | Daniel Jasper <djasper@google.com> | 2014-03-11 09:29:46 +0000 | 
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-03-11 09:29:46 +0000 | 
| commit | c580af96fac3ecb374ca82ae6a0a8caba6a44d33 (patch) | |
| tree | 0276396e8a1f2870ecc40a01edec367f43cea163 | |
| parent | 020b32de0d7f9a2065257ff4cbef2caa1247f787 (diff) | |
| download | bcm5719-llvm-c580af96fac3ecb374ca82ae6a0a8caba6a44d33.tar.gz bcm5719-llvm-c580af96fac3ecb374ca82ae6a0a8caba6a44d33.zip | |
clang-format: Detect weird macro lambda usage.
Before:
  void f() {
    MACRO((const AA & a) { return 1; });
  }
After:
  void f() {
    MACRO((const AA &a) { return 1; });
  }
llvm-svn: 203551
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 6 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 5 | 
2 files changed, 10 insertions, 1 deletions
| diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index bb91fa7f52c..34aef99a7b2 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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) && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 6e8e955dda5..d3ad9fb5d3b 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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) { | 

