clang-format: Add an option 'SpaceAfterCStyleCast'.
This permits to add a space after closing parenthesis of a C-style cast.
Defaults to false to preserve old behavior.
Fixes llvm.org/PR19982.
Before:
(int)i;
After:
(int) i;
Patch by Marek Kurdej.
llvm-svn: 217022
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 451e834..6f00acf 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -7721,6 +7721,38 @@
"default:\n"
" break;\n"
"}", Spaces);
+
+ Spaces.SpaceAfterCStyleCast = true;
+ verifyFormat("call(x, y, z);", Spaces);
+ verifyFormat("while (( bool ) 1)\n"
+ " continue;",
+ Spaces);
+ verifyFormat("for (;;)\n"
+ " continue;",
+ Spaces);
+ verifyFormat("if (true)\n"
+ " f( );\n"
+ "else if (true)\n"
+ " f( );",
+ Spaces);
+ verifyFormat("do {\n"
+ " do_something(( int ) i);\n"
+ "} while (something( ));",
+ Spaces);
+ verifyFormat("switch (x) {\n"
+ "default:\n"
+ " break;\n"
+ "}",
+ Spaces);
+ Spaces.SpacesInCStyleCastParentheses = false;
+ Spaces.SpaceAfterCStyleCast = true;
+ verifyFormat("while ((bool) 1)\n"
+ " continue;",
+ Spaces);
+ verifyFormat("do {\n"
+ " do_something((int) i);\n"
+ "} while (something( ));",
+ Spaces);
}
TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {
@@ -8306,6 +8338,7 @@
CHECK_PARSE_BOOL(SpaceInEmptyParentheses);
CHECK_PARSE_BOOL(SpacesInContainerLiterals);
CHECK_PARSE_BOOL(SpacesInCStyleCastParentheses);
+ CHECK_PARSE_BOOL(SpaceAfterCStyleCast);
CHECK_PARSE_BOOL(SpaceBeforeAssignmentOperators);
}