}
}
+ * ``SBPO_ControlStatementsExceptForEachMacros`` (in configuration: ``ControlStatementsExceptForEachMacros``)
+ Same as ``SBPO_ControlStatements`` except this option doesn't apply to
+ ForEach macros. This is useful in projects where ForEach macros are
+ treated as function calls instead of control statements.
+
+ .. code-block:: c++
+
+ void f() {
+ Q_FOREACH(...) {
+ f();
+ }
+ }
+
* ``SBPO_NonEmptyParentheses`` (in configuration: ``NonEmptyParentheses``)
Put a space before opening parentheses only if the parentheses are not
empty i.e. '()'
/// }
/// \endcode
SBPO_ControlStatements,
+ /// Same as ``SBPO_ControlStatements`` except this option doesn't apply to
+ /// ForEach macros. This is useful in projects where ForEach macros are
+ /// treated as function calls instead of control statements.
+ /// \code
+ /// void f() {
+ /// Q_FOREACH(...) {
+ /// f();
+ /// }
+ /// }
+ /// \endcode
+ SBPO_ControlStatementsExceptForEachMacros,
/// Put a space before opening parentheses only if the parentheses are not
/// empty i.e. '()'
/// \code
IO.enumCase(Value, "Never", FormatStyle::SBPO_Never);
IO.enumCase(Value, "ControlStatements",
FormatStyle::SBPO_ControlStatements);
+ IO.enumCase(Value, "ControlStatementsExceptForEachMacros",
+ FormatStyle::SBPO_ControlStatementsExceptForEachMacros);
IO.enumCase(Value, "NonEmptyParentheses",
FormatStyle::SBPO_NonEmptyParentheses);
IO.enumCase(Value, "Always", FormatStyle::SBPO_Always);
if ((Left.is(tok::r_paren) && Left.is(TT_AttributeParen)) ||
(Left.is(tok::r_square) && Left.is(TT_AttributeSquare)))
return true;
+ if (Style.SpaceBeforeParens ==
+ FormatStyle::SBPO_ControlStatementsExceptForEachMacros &&
+ Left.is(TT_ForEachMacro))
+ return false;
return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||
(Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
(Left.isOneOf(tok::pp_elif, tok::kw_for, tok::kw_while,
" UNKNOWN_FORACH(Item * item, itemlist) {}\n"
"}");
+ FormatStyle Style = getLLVMStyle();
+ Style.SpaceBeforeParens =
+ FormatStyle::SBPO_ControlStatementsExceptForEachMacros;
+ verifyFormat("void f() {\n"
+ " foreach(Item *item, itemlist) {}\n"
+ " Q_FOREACH(Item *item, itemlist) {}\n"
+ " BOOST_FOREACH(Item *item, itemlist) {}\n"
+ " UNKNOWN_FORACH(Item * item, itemlist) {}\n"
+ "}",
+ Style);
+
// As function-like macros.
verifyFormat("#define foreach(x, y)\n"
"#define Q_FOREACH(x, y)\n"