From f439dcb4ecb444df538c42b3284c093886fc7ab1 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 28 Aug 2013 07:50:37 +0000 Subject: [PATCH] clang-format: Improve braced init list detection: Before: std::this_thread::sleep_for(std::chrono::nanoseconds{ std::chrono::seconds { 1 } } / 5); After: std::this_thread::sleep_for( std::chrono::nanoseconds{ std::chrono::seconds{ 1 } } / 5); This fixes llvm.org/PR16554. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189451 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/UnwrappedLineParser.cpp | 6 +++++- unittests/Format/FormatTest.cpp | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index d77f931b71..168b59e8ee 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -284,8 +284,12 @@ void UnwrappedLineParser::calculateBraceTypes() { // Thus, if the parent is a braced init list, we consider all // brace blocks inside it braced init list. That works good enough // for now, but we will need to fix it to correctly handle lambdas. + // + // We exclude + and - as they can be ObjC visibility modifiers. if (NextTok->isOneOf(tok::comma, tok::semi, tok::r_paren, - tok::l_brace, tok::colon)) { + tok::l_brace, tok::colon) || + (NextTok->isBinaryOperator() && + !NextTok->isOneOf(tok::plus, tok::minus))) { Tok->BlockKind = BK_BracedInit; LBraceStack.back()->BlockKind = BK_BracedInit; } else { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 51ada26a20..274d6e0064 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4159,6 +4159,9 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) { " // comment 2\n" " param3, param4\n" " });"); + verifyFormat( + "std::this_thread::sleep_for(\n" + " std::chrono::nanoseconds{ std::chrono::seconds{ 1 } } / 5);"); FormatStyle NoSpaces = getLLVMStyle(); NoSpaces.Cpp11BracedListStyle = true; -- 2.40.0