@@ -4151,17 +4151,10 @@ struct FormatStyle {
4151
4151
bool SpaceInEmptyBlock;
4152
4152
4153
4153
// / If ``true``, spaces may be inserted into ``()``.
4154
- // / \code
4155
- // / true: false:
4156
- // / void f( ) { vs. void f() {
4157
- // / int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
4158
- // / if (true) { if (true) {
4159
- // / f( ); f();
4160
- // / } }
4161
- // / } }
4162
- // / \endcode
4154
+ // / This option is **deprecated**. See ``InEmptyParentheses`` of
4155
+ // / ``SpacesInParensOptions``.
4163
4156
// / \version 3.7
4164
- bool SpaceInEmptyParentheses;
4157
+ // bool SpaceInEmptyParentheses;
4165
4158
4166
4159
// / The number of spaces before trailing line comments
4167
4160
// / (``//`` - comments).
@@ -4208,13 +4201,10 @@ struct FormatStyle {
4208
4201
4209
4202
// / If ``true``, spaces will be inserted around if/for/switch/while
4210
4203
// / conditions.
4211
- // / \code
4212
- // / true: false:
4213
- // / if ( a ) { ... } vs. if (a) { ... }
4214
- // / while ( i < 5 ) { ... } while (i < 5) { ... }
4215
- // / \endcode
4204
+ // / This option is **deprecated**. See ``InConditionalStatements`` of
4205
+ // / ``SpacesInParensOptions``.
4216
4206
// / \version 10
4217
- bool SpacesInConditionalStatement;
4207
+ // bool SpacesInConditionalStatement;
4218
4208
4219
4209
// / If ``true``, spaces are inserted inside container literals (e.g. ObjC and
4220
4210
// / Javascript array and dict literals). For JSON, use
@@ -4228,12 +4218,10 @@ struct FormatStyle {
4228
4218
bool SpacesInContainerLiterals;
4229
4219
4230
4220
// / If ``true``, spaces may be inserted into C style casts.
4231
- // / \code
4232
- // / true: false:
4233
- // / x = ( int32 )y vs. x = (int32)y
4234
- // / \endcode
4221
+ // / This option is **deprecated**. See ``InCStyleCasts`` of
4222
+ // / ``SpacesInParensOptions``.
4235
4223
// / \version 3.7
4236
- bool SpacesInCStyleCastParentheses;
4224
+ // bool SpacesInCStyleCastParentheses;
4237
4225
4238
4226
// / Control of spaces within a single line comment.
4239
4227
struct SpacesInLineComment {
@@ -4277,13 +4265,112 @@ struct FormatStyle {
4277
4265
// / \version 13
4278
4266
SpacesInLineComment SpacesInLineCommentPrefix;
4279
4267
4280
- // / If ``true``, spaces will be inserted after ``(`` and before ``)``.
4268
+ // / Different ways to put a space before opening and closing parentheses.
4269
+ enum SpacesInParensStyle : int8_t {
4270
+ // / Never put a space in parentheses.
4271
+ // / \code
4272
+ // / void f() {
4273
+ // / if(true) {
4274
+ // / f();
4275
+ // / }
4276
+ // / }
4277
+ // / \endcode
4278
+ SIPO_Never,
4279
+ // / Configure each individual space in parentheses in
4280
+ // / `SpacesInParensOptions`.
4281
+ SIPO_Custom,
4282
+ };
4283
+
4284
+ // / If ``true'', spaces will be inserted after ``(`` and before ``)``.
4285
+ // / This option is **deprecated**. The previous behavior is preserved by using
4286
+ // / ``SpacesInParens`` with ``Custom`` and by setting all
4287
+ // / ``SpacesInParensOptions`` to ``true`` except for ``InCStyleCasts`` and
4288
+ // / ``InEmptyParentheses``.
4289
+ // / \version 3.7
4290
+ // bool SpacesInParentheses;
4291
+
4292
+ // / Defines in which cases spaces will be inserted after ``(`` and before
4293
+ // / ``)``.
4294
+ // / \version 17
4295
+ SpacesInParensStyle SpacesInParens;
4296
+
4297
+ // / Precise control over the spacing in parentheses.
4281
4298
// / \code
4282
- // / true: false:
4283
- // / t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
4299
+ // / # Should be declared this way:
4300
+ // / SpacesInParens: Custom
4301
+ // / SpacesInParensOptions:
4302
+ // / InConditionalStatements: true
4303
+ // / Other: true
4284
4304
// / \endcode
4285
- // / \version 3.7
4286
- bool SpacesInParentheses;
4305
+ struct SpacesInParensCustom {
4306
+ // / Put a space in parentheses only inside conditional statements
4307
+ // / (``for/if/while/switch...``).
4308
+ // / \code
4309
+ // / true: false:
4310
+ // / if ( a ) { ... } vs. if (a) { ... }
4311
+ // / while ( i < 5 ) { ... } while (i < 5) { ... }
4312
+ // / \endcode
4313
+ bool InConditionalStatements;
4314
+ // / Put a space in C style casts.
4315
+ // / \code
4316
+ // / true: false:
4317
+ // / x = ( int32 )y vs. x = (int32)y
4318
+ // / \endcode
4319
+ bool InCStyleCasts;
4320
+ // / Put a space in parentheses only if the parentheses are empty i.e. '()'
4321
+ // / \code
4322
+ // / true: false:
4323
+ // / void f( ) { vs. void f() {
4324
+ // / int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
4325
+ // / if (true) { if (true) {
4326
+ // / f( ); f();
4327
+ // / } }
4328
+ // / } }
4329
+ // / \endcode
4330
+ bool InEmptyParentheses;
4331
+ // / Put a space in parentheses not covered by preceding options.
4332
+ // / \code
4333
+ // / true: false:
4334
+ // / t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
4335
+ // / \endcode
4336
+ bool Other;
4337
+
4338
+ SpacesInParensCustom ()
4339
+ : InConditionalStatements(false ), InCStyleCasts(false ),
4340
+ InEmptyParentheses (false ), Other(false ) {}
4341
+
4342
+ SpacesInParensCustom (bool InConditionalStatements, bool InCStyleCasts,
4343
+ bool InEmptyParentheses, bool Other)
4344
+ : InConditionalStatements(InConditionalStatements),
4345
+ InCStyleCasts(InCStyleCasts),
4346
+ InEmptyParentheses(InEmptyParentheses),
4347
+ Other(Other) {}
4348
+
4349
+ bool operator ==(const SpacesInParensCustom &R) const {
4350
+ return InConditionalStatements == R.InConditionalStatements &&
4351
+ InCStyleCasts == R.InCStyleCasts &&
4352
+ InEmptyParentheses == R.InEmptyParentheses &&
4353
+ Other == R.Other ;
4354
+ }
4355
+ bool operator !=(const SpacesInParensCustom &R) const {
4356
+ return !(*this == R);
4357
+ }
4358
+ };
4359
+
4360
+ // / Control of individual spaces in parentheses.
4361
+ // /
4362
+ // / If ``SpacesInParens`` is set to ``Custom``, use this to specify
4363
+ // / how each individual space in parentheses case should be handled.
4364
+ // / Otherwise, this is ignored.
4365
+ // / \code{.yaml}
4366
+ // / # Example of usage:
4367
+ // / SpacesInParens: Custom
4368
+ // / SpacesInParensOptions:
4369
+ // / InConditionalStatements: true
4370
+ // / InEmptyParentheses: true
4371
+ // / \endcode
4372
+ // / \version 17
4373
+ SpacesInParensCustom SpacesInParensOptions;
4287
4374
4288
4375
// / If ``true``, spaces will be inserted after ``[`` and before ``]``.
4289
4376
// / Lambdas without arguments or unspecified size array declarations will not
@@ -4587,17 +4674,15 @@ struct FormatStyle {
4587
4674
R.SpaceBeforeRangeBasedForLoopColon &&
4588
4675
SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets &&
4589
4676
SpaceInEmptyBlock == R.SpaceInEmptyBlock &&
4590
- SpaceInEmptyParentheses == R.SpaceInEmptyParentheses &&
4591
4677
SpacesBeforeTrailingComments == R.SpacesBeforeTrailingComments &&
4592
4678
SpacesInAngles == R.SpacesInAngles &&
4593
- SpacesInConditionalStatement == R.SpacesInConditionalStatement &&
4594
4679
SpacesInContainerLiterals == R.SpacesInContainerLiterals &&
4595
- SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses &&
4596
4680
SpacesInLineCommentPrefix.Minimum ==
4597
4681
R.SpacesInLineCommentPrefix .Minimum &&
4598
4682
SpacesInLineCommentPrefix.Maximum ==
4599
4683
R.SpacesInLineCommentPrefix .Maximum &&
4600
- SpacesInParentheses == R.SpacesInParentheses &&
4684
+ SpacesInParens == R.SpacesInParens &&
4685
+ SpacesInParensOptions == R.SpacesInParensOptions &&
4601
4686
SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
4602
4687
Standard == R.Standard &&
4603
4688
StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
0 commit comments