Skip to content

Commit 7714c5a

Browse files
committed
Address review comments
1 parent 3a1c901 commit 7714c5a

File tree

4 files changed

+8
-227
lines changed

4 files changed

+8
-227
lines changed

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6232,8 +6232,7 @@ the configuration (without a prefix: ``Auto``).
62326232
Other: true
62336233

62346234
* ``bool ExceptDoubleParentheses`` Override any of the following options to prevent addition of space
6235-
between the first two parentheses in situations where a pair of
6236-
parentheses have been used.
6235+
when both opening and closing parentheses use multiple parentheses.
62376236

62386237
.. code-block:: c++
62396238

@@ -6279,10 +6278,6 @@ the configuration (without a prefix: ``Auto``).
62796278

62806279
true: false:
62816280
t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
6282-
decltype( ( x ) ) decltype((x))
6283-
x = ( (int32)y ) x = ((int32))y
6284-
y = ( (int ( * )( int ))foo )( x ); y = ((int (*)(int))foo)(x);
6285-
__attribute__( ( noreturn ) ) __attribute__((noreturn))
62866281

62876282

62886283
.. _SpacesInParentheses:

clang/include/clang/Format/Format.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4656,8 +4656,7 @@ struct FormatStyle {
46564656
/// \endcode
46574657
struct SpacesInParensCustom {
46584658
/// Override any of the following options to prevent addition of space
4659-
/// between the first two parentheses in situations where a pair of
4660-
/// parentheses have been used.
4659+
/// when both opening and closing parentheses use multiple parentheses.
46614660
/// \code
46624661
/// true:
46634662
/// __attribute__(( noreturn ))
@@ -4697,10 +4696,6 @@ struct FormatStyle {
46974696
/// \code
46984697
/// true: false:
46994698
/// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
4700-
/// decltype( ( x ) ) decltype((x))
4701-
/// x = ( (int32)y ) x = ((int32))y
4702-
/// y = ( (int ( * )( int ))foo )( x ); y = ((int (*)(int))foo)(x);
4703-
/// __attribute__( ( noreturn ) ) __attribute__((noreturn))
47044699
/// \endcode
47054700
bool Other;
47064701

clang/lib/Format/Format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ template <> struct MappingTraits<FormatStyle> {
11761176
(SpacesInParentheses || SpaceInEmptyParentheses ||
11771177
SpacesInConditionalStatement || SpacesInCStyleCastParentheses)) {
11781178
if (SpacesInParentheses) {
1179-
// for backward compatibility.
1179+
// For backward compatibility.
11801180
Style.SpacesInParensOptions.ExceptDoubleParentheses = false;
11811181
Style.SpacesInParensOptions.InConditionalStatements = true;
11821182
Style.SpacesInParensOptions.InCStyleCasts =

clang/unittests/Format/FormatTest.cpp

Lines changed: 5 additions & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -17368,16 +17368,6 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
1736817368
Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
1736917369
Spaces.SpacesInParensOptions = {};
1737017370
Spaces.SpacesInParensOptions.Other = true;
17371-
verifyFormat("SomeType *__attribute__( ( attr ) ) *a = NULL;", Spaces);
17372-
verifyFormat("void __attribute__( ( naked ) ) foo( int bar )", Spaces);
17373-
verifyFormat("void f() __attribute__( ( asdf ) );", Spaces);
17374-
verifyFormat("__attribute__( ( __aligned__( x ) ) ) z;", Spaces);
17375-
verifyFormat("int x __attribute__( ( aligned( 16 ) ) ) = 0;", Spaces);
17376-
verifyFormat("class __declspec( dllimport ) X {};", Spaces);
17377-
verifyFormat("class __declspec( ( dllimport ) ) X {};", Spaces);
17378-
verifyFormat("int x = ( ( a - 1 ) * 3 );", Spaces);
17379-
verifyFormat("int x = ( 3 * ( a - 1 ) );", Spaces);
17380-
1738117371
Spaces.SpacesInParensOptions.ExceptDoubleParentheses = true;
1738217372
verifyFormat("SomeType *__attribute__(( attr )) *a = NULL;", Spaces);
1738317373
verifyFormat("void __attribute__(( naked )) foo( int bar )", Spaces);
@@ -17388,96 +17378,22 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
1738817378
verifyFormat("class __declspec(( dllimport )) X {};", Spaces);
1738917379
verifyFormat("int x = ( ( a - 1 ) * 3 );", Spaces);
1739017380
verifyFormat("int x = ( 3 * ( a - 1 ) );", Spaces);
17391-
17392-
Spaces.SpacesInParensOptions.Other = false;
17393-
verifyFormat("SomeType *__attribute__((attr)) *a = NULL;", Spaces);
17394-
verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces);
17395-
verifyFormat("void f() __attribute__((asdf));", Spaces);
17396-
verifyFormat("__attribute__((__aligned__(x))) z;", Spaces);
17397-
verifyFormat("int x __attribute__((aligned(16))) = 0;", Spaces);
17398-
verifyFormat("class __declspec(dllimport) X {};", Spaces);
17399-
verifyFormat("class __declspec((dllimport)) X {};", Spaces);
17400-
17401-
Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
17402-
Spaces.SpacesInParensOptions = {};
17403-
Spaces.SpacesInParensOptions.InCStyleCasts = true;
17404-
verifyFormat("x = ( int32 )y;", Spaces);
17405-
verifyFormat("y = (( int (*)(int) )foo)(x);", Spaces);
17406-
17407-
Spaces.SpacesInParensOptions.ExceptDoubleParentheses = true;
17408-
verifyFormat("x = ( int32 )y;", Spaces);
17409-
verifyFormat("y = (( int (*)(int) )foo)(x);", Spaces);
17410-
17411-
Spaces.SpacesInParensOptions.InCStyleCasts = false;
17412-
verifyFormat("x = (int32)y;", Spaces);
17413-
verifyFormat("y = ((int (*)(int))foo)(x);", Spaces);
17381+
verifyFormat("decltype( x ) y = 42;", Spaces);
17382+
verifyFormat("decltype(( bar( 10 ) )) a = bar( 11 );", Spaces);
17383+
verifyFormat("if (( i = j ))\n"
17384+
" do_something( i );",
17385+
Spaces);
1741417386

1741517387
Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
1741617388
Spaces.SpacesInParensOptions = {};
1741717389
Spaces.SpacesInParensOptions.InConditionalStatements = true;
17418-
verifyFormat("while ( (bool)1 )\n"
17419-
" continue;",
17420-
Spaces);
17421-
verifyFormat("while ( (i = j) )\n"
17422-
" continue;",
17423-
Spaces);
17424-
verifyFormat("for ( ;; )\n"
17425-
" continue;",
17426-
Spaces);
17427-
verifyFormat("if ( true )\n"
17428-
" f();\n"
17429-
"else if ( true )\n"
17430-
" f();",
17431-
Spaces);
17432-
verifyFormat("do {\n"
17433-
" do_something((int)i);\n"
17434-
"} while ( something() );",
17435-
Spaces);
17436-
verifyFormat("do {\n"
17437-
" do_something((int)i);\n"
17438-
"} while ( (i = i + 1) );",
17439-
Spaces);
17440-
verifyFormat("switch ( x ) {\n"
17441-
"default:\n"
17442-
" break;\n"
17443-
"}",
17444-
Spaces);
17445-
verifyFormat("if ( (x - y) && (a ^ b) )\n"
17446-
" f();\n",
17447-
Spaces);
17448-
verifyFormat("if ( (i = j) )\n"
17449-
" do_something(i);",
17450-
Spaces);
17451-
verifyFormat("for ( int i = 0; i < 10; i = (i + 1) )\n"
17452-
" foo(i);",
17453-
Spaces);
17454-
verifyFormat("switch ( x / (y + z) ) {\n"
17455-
"default:\n"
17456-
" break;\n"
17457-
"}",
17458-
Spaces);
17459-
verifyFormat("if constexpr ( (a = b) )\n"
17460-
" c;",
17461-
Spaces);
17462-
verifyFormat("if ( ({ a; }) )\n"
17463-
" b;",
17464-
Spaces);
17465-
1746617390
Spaces.SpacesInParensOptions.ExceptDoubleParentheses = true;
1746717391
verifyFormat("while ( (bool)1 )\n"
1746817392
" continue;",
1746917393
Spaces);
1747017394
verifyFormat("while ((i = j))\n"
1747117395
" continue;",
1747217396
Spaces);
17473-
verifyFormat("for ( ;; )\n"
17474-
" continue;",
17475-
Spaces);
17476-
verifyFormat("if ( true )\n"
17477-
" f();\n"
17478-
"else if ( true )\n"
17479-
" f();",
17480-
Spaces);
1748117397
verifyFormat("do {\n"
1748217398
" do_something((int)i);\n"
1748317399
"} while ( something() );",
@@ -17486,11 +17402,6 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
1748617402
" do_something((int)i);\n"
1748717403
"} while ((i = i + 1));",
1748817404
Spaces);
17489-
verifyFormat("switch ( x ) {\n"
17490-
"default:\n"
17491-
" break;\n"
17492-
"}",
17493-
Spaces);
1749417405
verifyFormat("if ( (x - y) && (a ^ b) )\n"
1749517406
" f();\n",
1749617407
Spaces);
@@ -17508,126 +17419,6 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
1750817419
verifyFormat("if constexpr ((a = b))\n"
1750917420
" c;",
1751017421
Spaces);
17511-
17512-
Spaces.SpacesInParensOptions.InConditionalStatements = false;
17513-
verifyFormat("while ((bool)1)\n"
17514-
" continue;",
17515-
Spaces);
17516-
verifyFormat("while ((i = j))\n"
17517-
" continue;",
17518-
Spaces);
17519-
verifyFormat("for (;;)\n"
17520-
" continue;",
17521-
Spaces);
17522-
verifyFormat("if (true)\n"
17523-
" f();\n"
17524-
"else if (true)\n"
17525-
" f();",
17526-
Spaces);
17527-
verifyFormat("do {\n"
17528-
" do_something((int)i);\n"
17529-
"} while (something());",
17530-
Spaces);
17531-
verifyFormat("do {\n"
17532-
" do_something((int)i);\n"
17533-
"} while ((i = i + 1));",
17534-
Spaces);
17535-
verifyFormat("switch (x) {\n"
17536-
"default:\n"
17537-
" break;\n"
17538-
"}",
17539-
Spaces);
17540-
verifyFormat("if ((x - y) && (a ^ b))\n"
17541-
" f();\n",
17542-
Spaces);
17543-
verifyFormat("if ((i = j))\n"
17544-
" do_something(i);",
17545-
Spaces);
17546-
verifyFormat("for (int i = 0; i < 10; i = (i + 1))\n"
17547-
" foo(i);",
17548-
Spaces);
17549-
verifyFormat("switch (x / (y + z)) {\n"
17550-
"default:\n"
17551-
" break;\n"
17552-
"}",
17553-
Spaces);
17554-
verifyFormat("if constexpr ((a = b))\n"
17555-
" c;",
17556-
Spaces);
17557-
17558-
Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
17559-
Spaces.SpacesInParensOptions = {};
17560-
Spaces.SpacesInParensOptions.Other = true;
17561-
verifyFormat("decltype( x ) y = 42;", Spaces);
17562-
verifyFormat("decltype( ( x ) ) y = z;", Spaces);
17563-
verifyFormat("decltype( ( foo() ) ) a = foo();", Spaces);
17564-
verifyFormat("decltype( ( bar( 10 ) ) ) a = bar( 11 );", Spaces);
17565-
verifyFormat("decltype( ( foo->bar ) ) baz;", Spaces);
17566-
verifyFormat("if ( ( i = j ) )\n"
17567-
" do_something( i );",
17568-
Spaces);
17569-
verifyFormat("if constexpr ( ( a = b ) )\n"
17570-
" c;",
17571-
Spaces);
17572-
17573-
Spaces.SpacesInParensOptions.ExceptDoubleParentheses = true;
17574-
verifyFormat("decltype( x ) y = 42;", Spaces);
17575-
verifyFormat("decltype(( x )) y = z;", Spaces);
17576-
verifyFormat("decltype(( foo() )) a = foo();", Spaces);
17577-
verifyFormat("decltype(( bar( 10 ) )) a = bar( 11 );", Spaces);
17578-
verifyFormat("decltype(( foo->bar )) baz;", Spaces);
17579-
verifyFormat("if (( i = j ))\n"
17580-
" do_something( i );",
17581-
Spaces);
17582-
verifyFormat("if constexpr (( a = b ))\n"
17583-
" c;",
17584-
Spaces);
17585-
17586-
Spaces.SpacesInParensOptions.Other = false;
17587-
verifyFormat("decltype(x) y = 42;", Spaces);
17588-
verifyFormat("decltype((x)) y = z;", Spaces);
17589-
verifyFormat("decltype((foo())) a = foo();", Spaces);
17590-
verifyFormat("decltype((bar(10))) a = bar(11);", Spaces);
17591-
verifyFormat("decltype((foo->bar)) baz;", Spaces);
17592-
verifyFormat("if ((i = j))\n"
17593-
" do_something(i);",
17594-
Spaces);
17595-
verifyFormat("if constexpr ((a = b))\n"
17596-
" c;",
17597-
Spaces);
17598-
17599-
Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
17600-
Spaces.SpacesInParensOptions = {};
17601-
Spaces.SpacesInParensOptions.Other = true;
17602-
Spaces.SpacesInParensOptions.InConditionalStatements = true;
17603-
verifyFormat("if ( ( i = j ) )\n"
17604-
" do_something( i );",
17605-
Spaces);
17606-
verifyFormat("if constexpr ( ( a = b ) )\n"
17607-
" c;",
17608-
Spaces);
17609-
verifyFormat("while ( ( i = j ) )\n"
17610-
" continue;",
17611-
Spaces);
17612-
verifyFormat("do {\n"
17613-
" do_something( (int)i );\n"
17614-
"} while ( ( i = i + 1 ) );",
17615-
Spaces);
17616-
17617-
Spaces.SpacesInParensOptions.ExceptDoubleParentheses = true;
17618-
verifyFormat("if (( i = j ))\n"
17619-
" do_something( i );",
17620-
Spaces);
17621-
verifyFormat("if constexpr (( a = b ))\n"
17622-
" c;",
17623-
Spaces);
17624-
verifyFormat("while (( i = j ))\n"
17625-
" continue;",
17626-
Spaces);
17627-
verifyFormat("do {\n"
17628-
" do_something( (int)i );\n"
17629-
"} while (( i = i + 1 ));",
17630-
Spaces);
1763117422
}
1763217423

1763317424
TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {

0 commit comments

Comments
 (0)