diff options
Diffstat (limited to 'clang')
| -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) { |

