@@ -4346,6 +4346,28 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
4346
4346
Right.is (tok::r_brace) && Right.isNot (BK_Block))) {
4347
4347
return Style.SpacesInParensOptions .InEmptyParentheses ;
4348
4348
}
4349
+ if (Style.SpacesInParens == FormatStyle::SIPO_Custom &&
4350
+ Style.SpacesInParensOptions .ExceptDoubleParentheses &&
4351
+ Left.is (tok::r_paren) && Right.is (tok::r_paren)) {
4352
+ auto *InnerLParen = Left.MatchingParen ;
4353
+ if (InnerLParen && InnerLParen->Previous == Right.MatchingParen ) {
4354
+ InnerLParen->SpacesRequiredBefore = 0 ;
4355
+ return false ;
4356
+ }
4357
+ }
4358
+ if (Style.SpacesInParensOptions .InConditionalStatements ) {
4359
+ const FormatToken *LeftParen = nullptr ;
4360
+ if (Left.is (tok::l_paren))
4361
+ LeftParen = &Left;
4362
+ else if (Right.is (tok::r_paren) && Right.MatchingParen )
4363
+ LeftParen = Right.MatchingParen ;
4364
+ if (LeftParen) {
4365
+ if (LeftParen->is (TT_ConditionLParen))
4366
+ return true ;
4367
+ if (LeftParen->Previous && isKeywordWithCondition (*LeftParen->Previous ))
4368
+ return true ;
4369
+ }
4370
+ }
4349
4371
4350
4372
// trailing return type 'auto': []() -> auto {}, auto foo() -> auto {}
4351
4373
if (Left.is (tok::kw_auto) && Right.isOneOf (TT_LambdaLBrace, TT_FunctionLBrace,
@@ -4372,60 +4394,11 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
4372
4394
}
4373
4395
4374
4396
if (Left.is (tok::l_paren) || Right.is (tok::r_paren)) {
4375
- const FormatToken *LeftParen =
4376
- Left.is (tok::l_paren) ? &Left : Right.MatchingParen ;
4377
- const FormatToken *RightParen =
4378
- LeftParen ? LeftParen->MatchingParen : nullptr ;
4379
- const auto IsAttributeParen = [](const FormatToken *Paren) {
4380
- return Paren && Paren->isOneOf (TT_AttributeLParen, TT_AttributeRParen);
4381
- };
4382
- auto AddSpaceExceptInDoubleParens = [&]() {
4383
- const auto *RPrev = RightParen ? RightParen->Previous : nullptr ;
4384
- const auto *LNext = LeftParen->Next ;
4385
- const auto *LPrev = LeftParen->Previous ;
4386
- if (!(RPrev && RPrev->is (tok::r_paren) && LNext &&
4387
- LNext->is (tok::l_paren))) {
4388
- return true ;
4389
- }
4390
- auto HasEqualBeforeNextParen = [&]() {
4391
- auto *Tok = LNext;
4392
- if (!Tok || !Tok->is (tok::l_paren))
4393
- return false ;
4394
- while ((Tok = Tok->Next ) && !Tok->isOneOf (tok::l_paren, tok::r_paren))
4395
- if (Tok->is (tok::equal))
4396
- return true ;
4397
- return false ;
4398
- };
4399
- const bool SuppressSpace =
4400
- IsAttributeParen (LeftParen) ||
4401
- (LPrev && (LPrev->isOneOf (tok::kw___attribute, tok::kw_decltype) ||
4402
- (HasEqualBeforeNextParen () &&
4403
- (LPrev->isOneOf (tok::kw_if, tok::kw_while) ||
4404
- LPrev->endsSequence (tok::kw_constexpr, tok::kw_if)))));
4405
- return !SuppressSpace;
4406
- };
4407
- const auto AddSpace = [&](bool Option) {
4408
- if (Style.SpacesInParensOptions .ExceptDoubleParentheses && Option)
4409
- return AddSpaceExceptInDoubleParens ();
4410
- return Option;
4411
- };
4412
-
4413
- if (LeftParen && (LeftParen->is (TT_ConditionLParen) ||
4414
- (LeftParen->Previous &&
4415
- isKeywordWithCondition (*LeftParen->Previous )))) {
4416
- return AddSpace (Style.SpacesInParensOptions .InConditionalStatements );
4417
- }
4418
- if (RightParen && RightParen->is (TT_CastRParen))
4419
- return AddSpace (Style.SpacesInParensOptions .InCStyleCasts );
4420
- if (IsAttributeParen (LeftParen) || IsAttributeParen (RightParen))
4421
- return AddSpace (Style.SpacesInParensOptions .Other );
4422
- if ((LeftParen && IsAttributeParen (LeftParen->Previous )) ||
4423
- (RightParen && IsAttributeParen (RightParen->Next ))) {
4424
- return AddSpace (Style.SpacesInParensOptions .Other );
4425
- }
4426
- return AddSpace (Style.SpacesInParensOptions .Other );
4397
+ return (Right.is (TT_CastRParen) ||
4398
+ (Left.MatchingParen && Left.MatchingParen ->is (TT_CastRParen)))
4399
+ ? Style.SpacesInParensOptions .InCStyleCasts
4400
+ : Style.SpacesInParensOptions .Other ;
4427
4401
}
4428
-
4429
4402
if (Right.isOneOf (tok::semi, tok::comma))
4430
4403
return false ;
4431
4404
if (Right.is (tok::less) && Line.Type == LT_ObjCDecl) {
0 commit comments