diff options
| author | Daniel Jasper <djasper@google.com> | 2013-08-28 07:50:37 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2013-08-28 07:50:37 +0000 |
| commit | 65b79829c365042eac1d5ad4f7e2a17a152034b8 (patch) | |
| tree | 0aafd72e252f429476dd2864985f64ef1f6ad933 /clang | |
| parent | d215b8bde2137c4856c11cbe76864cddd63e5b3e (diff) | |
| download | bcm5719-llvm-65b79829c365042eac1d5ad4f7e2a17a152034b8.tar.gz bcm5719-llvm-65b79829c365042eac1d5ad4f7e2a17a152034b8.zip | |
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.
llvm-svn: 189451
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 6 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 3 |
2 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index d77f931b718..168b59e8ee4 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 51ada26a206..274d6e0064b 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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; |

