[clang] [clang-format] Add SpacesInParensOption for filtering repeated parens (PR #77522)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 23 16:36:50 PDT 2024
================
@@ -17310,6 +17362,63 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
+
+ // Check ExceptDoubleParentheses spaces
+ Spaces.IndentWidth = 2;
+ Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+ Spaces.SpacesInParensOptions = {};
+ Spaces.SpacesInParensOptions.Other = true;
+ Spaces.SpacesInParensOptions.ExceptDoubleParentheses = true;
+ verifyFormat("SomeType *__attribute__(( attr )) *a = NULL;", Spaces);
+ verifyFormat("void __attribute__(( naked )) foo( int bar )", Spaces);
+ verifyFormat("void f() __attribute__(( asdf ));", Spaces);
+ verifyFormat("__attribute__(( __aligned__( x ) )) z;", Spaces);
+ verifyFormat("int x __attribute__(( aligned( 16 ) )) = 0;", Spaces);
+ verifyFormat("class __declspec( dllimport ) X {};", Spaces);
+ verifyFormat("class __declspec(( dllimport )) X {};", Spaces);
+ verifyFormat("int x = ( ( a - 1 ) * 3 );", Spaces);
+ verifyFormat("int x = ( 3 * ( a - 1 ) );", Spaces);
+ verifyFormat("decltype( x ) y = 42;", Spaces);
+ verifyFormat("decltype(( bar( 10 ) )) a = bar( 11 );", Spaces);
+ verifyFormat("if (( i = j ))\n"
+ " do_something( i );",
+ Spaces);
+
+ Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
+ Spaces.SpacesInParensOptions = {};
+ Spaces.SpacesInParensOptions.InConditionalStatements = true;
+ Spaces.SpacesInParensOptions.ExceptDoubleParentheses = true;
+ verifyFormat("while ( (bool)1 )\n"
+ " continue;",
+ Spaces);
+ verifyFormat("while ((i = j))\n"
+ " continue;",
+ Spaces);
+ verifyFormat("do {\n"
+ " do_something((int)i);\n"
+ "} while ( something() );",
+ Spaces);
+ verifyFormat("do {\n"
+ " do_something((int)i);\n"
+ "} while ((i = i + 1));",
+ Spaces);
+ verifyFormat("if ( (x - y) && (a ^ b) )\n"
+ " f();\n",
----------------
owenca wrote:
Ditto.
https://github.com/llvm/llvm-project/pull/77522
More information about the cfe-commits
mailing list