forked from OSchip/llvm-project
clang-format: Fix braced list detection.
Before: static_assert(std::is_integral<int> {} + 0, ""); int a = std::is_integral<int> {} + 0; After: static_assert(std::is_integral<int>{} + 0, ""); int a = std::is_integral<int>{} + 0; llvm-svn: 209431
This commit is contained in:
parent
2dce43c26f
commit
91b032ab55
|
@ -338,6 +338,11 @@ void UnwrappedLineParser::calculateBraceTypes() {
|
||||||
if (Style.Language == FormatStyle::LK_Proto) {
|
if (Style.Language == FormatStyle::LK_Proto) {
|
||||||
ProbablyBracedList = NextTok->isOneOf(tok::comma, tok::r_square);
|
ProbablyBracedList = NextTok->isOneOf(tok::comma, tok::r_square);
|
||||||
} else {
|
} else {
|
||||||
|
// Using OriginalColumn to distinguish between ObjC methods and
|
||||||
|
// binary operators is a bit hacky.
|
||||||
|
bool NextIsObjCMethod = NextTok->isOneOf(tok::plus, tok::minus) &&
|
||||||
|
NextTok->OriginalColumn == 0;
|
||||||
|
|
||||||
// If there is a comma, semicolon or right paren after the closing
|
// If there is a comma, semicolon or right paren after the closing
|
||||||
// brace, we assume this is a braced initializer list. Note that
|
// brace, we assume this is a braced initializer list. Note that
|
||||||
// regardless how we mark inner braces here, we will overwrite the
|
// regardless how we mark inner braces here, we will overwrite the
|
||||||
|
@ -350,8 +355,7 @@ void UnwrappedLineParser::calculateBraceTypes() {
|
||||||
NextTok->isOneOf(tok::comma, tok::semi, tok::period, tok::colon,
|
NextTok->isOneOf(tok::comma, tok::semi, tok::period, tok::colon,
|
||||||
tok::r_paren, tok::r_square, tok::l_brace,
|
tok::r_paren, tok::r_square, tok::l_brace,
|
||||||
tok::l_paren) ||
|
tok::l_paren) ||
|
||||||
(NextTok->isBinaryOperator() &&
|
(NextTok->isBinaryOperator() && !NextIsObjCMethod);
|
||||||
!NextTok->isOneOf(tok::plus, tok::minus));
|
|
||||||
}
|
}
|
||||||
if (ProbablyBracedList) {
|
if (ProbablyBracedList) {
|
||||||
Tok->BlockKind = BK_BracedInit;
|
Tok->BlockKind = BK_BracedInit;
|
||||||
|
|
|
@ -5262,6 +5262,8 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
|
||||||
" T member = {arg1, arg2};\n"
|
" T member = {arg1, arg2};\n"
|
||||||
"};");
|
"};");
|
||||||
verifyFormat("vector<int> foo = {::SomeGlobalFunction()};");
|
verifyFormat("vector<int> foo = {::SomeGlobalFunction()};");
|
||||||
|
verifyFormat("static_assert(std::is_integral<int>{} + 0, \"\");");
|
||||||
|
verifyFormat("int a = std::is_integral<int>{} + 0;");
|
||||||
|
|
||||||
verifyFormat("int foo(int i) { return fo1{}(i); }");
|
verifyFormat("int foo(int i) { return fo1{}(i); }");
|
||||||
verifyFormat("int foo(int i) { return fo1{}(i); }");
|
verifyFormat("int foo(int i) { return fo1{}(i); }");
|
||||||
|
@ -6088,10 +6090,14 @@ TEST_F(FormatTest, FormatObjCImplementation) {
|
||||||
"@implementation Bar\n"
|
"@implementation Bar\n"
|
||||||
"@end");
|
"@end");
|
||||||
|
|
||||||
verifyFormat("@implementation Foo : Bar\n"
|
EXPECT_EQ("@implementation Foo : Bar\n"
|
||||||
"+ (id)init {\n}\n"
|
"+ (id)init {\n}\n"
|
||||||
"- (void)foo {\n}\n"
|
"- (void)foo {\n}\n"
|
||||||
"@end");
|
"@end",
|
||||||
|
format("@implementation Foo : Bar\n"
|
||||||
|
"+(id)init{}\n"
|
||||||
|
"-(void)foo{}\n"
|
||||||
|
"@end"));
|
||||||
|
|
||||||
verifyFormat("@implementation Foo {\n"
|
verifyFormat("@implementation Foo {\n"
|
||||||
" int _i;\n"
|
" int _i;\n"
|
||||||
|
|
Loading…
Reference in New Issue