]> granicus.if.org Git - clang/commitdiff
clang-format: Improve braced init list detection:
authorDaniel Jasper <djasper@google.com>
Wed, 28 Aug 2013 07:50:37 +0000 (07:50 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 28 Aug 2013 07:50:37 +0000 (07:50 +0000)
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
unittests/Format/FormatTest.cpp

index d77f931b718de88226153347a42a1c45c5bde32f..168b59e8ee49d73e457e8abee180591a6c319d4d 100644 (file)
@@ -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 {
index 51ada26a206c7f9f2ccace1774db42fd4a6e92c2..274d6e0064bdf69a167ef826ebd9cad6854911ed 100644 (file)
@@ -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;