From 8378e8520c72c3f1ac96e14d85d4d6a0731aefa9 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 30 Jun 2015 11:32:22 +0000 Subject: [PATCH] clang-format: Properly parse parenthesis in braced lists. Among other things, this makes clang-format understand arbitrary blocks embedded in them, such as: SomeFunction({MACRO({ return output; }), b}); where MACRO could e.g. expand to a lambda. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241059 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/UnwrappedLineParser.cpp | 5 ++--- unittests/Format/FormatTest.cpp | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 72652a7d0d..c58e6bccd9 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -1111,16 +1111,15 @@ bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons) { FormatTok->BlockKind = BK_BracedInit; parseBracedList(); break; - case tok::r_paren: + case tok::l_paren: + parseParens(); // JavaScript can just have free standing methods and getters/setters in // object literals. Detect them by a "{" following ")". if (Style.Language == FormatStyle::LK_JavaScript) { - nextToken(); if (FormatTok->is(tok::l_brace)) parseChildBlock(); break; } - nextToken(); break; case tok::r_brace: nextToken(); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 743171fb00..ef5299aada 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3184,6 +3184,8 @@ TEST_F(FormatTest, LayoutNestedBlocks) { "}, a);", Style); + verifyFormat("SomeFunction({MACRO({ return output; }), b});"); + verifyNoCrash("^{v^{a}}"); } -- 2.40.0