This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGda6b0d0b768e: [clang-format] Add an option to add a space between operator overloading and… (authored by rajatbajpai, committed by curdeius).
Changed prior to commit: https://reviews.llvm.org/D116283?vs=397112&id=397312#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D116283/new/ https://reviews.llvm.org/D116283 Files: clang/docs/ClangFormatStyleOptions.rst clang/docs/ReleaseNotes.rst clang/include/clang/Format/Format.h clang/lib/Format/Format.cpp clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -14536,6 +14536,24 @@ // verifyFormat("X A::operator++ (T);", SomeSpace2); verifyFormat("int x = int (y);", SomeSpace2); verifyFormat("auto lambda = []() { return 0; };", SomeSpace2); + + FormatStyle SpaceAfterOverloadedOperator = getLLVMStyle(); + SpaceAfterOverloadedOperator.SpaceBeforeParens = FormatStyle::SBPO_Custom; + SpaceAfterOverloadedOperator.SpaceBeforeParensOptions + .AfterOverloadedOperator = true; + + verifyFormat("auto operator++ () -> int;", SpaceAfterOverloadedOperator); + verifyFormat("X A::operator++ ();", SpaceAfterOverloadedOperator); + verifyFormat("some_object.operator++ ();", SpaceAfterOverloadedOperator); + verifyFormat("auto func() -> int;", SpaceAfterOverloadedOperator); + + SpaceAfterOverloadedOperator.SpaceBeforeParensOptions + .AfterOverloadedOperator = false; + + verifyFormat("auto operator++() -> int;", SpaceAfterOverloadedOperator); + verifyFormat("X A::operator++();", SpaceAfterOverloadedOperator); + verifyFormat("some_object.operator++();", SpaceAfterOverloadedOperator); + verifyFormat("auto func() -> int;", SpaceAfterOverloadedOperator); } TEST_F(FormatTest, SpaceAfterLogicalNot) { @@ -18771,6 +18789,15 @@ CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyFunction); CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyRecord); CHECK_PARSE_NESTED_BOOL(BraceWrapping, SplitEmptyNamespace); + CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterControlStatements); + CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterForeachMacros); + CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, + AfterFunctionDeclarationName); + CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, + AfterFunctionDefinitionName); + CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterIfMacros); + CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterOverloadedOperator); + CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, BeforeNonEmptyParentheses); } #undef CHECK_PARSE_BOOL Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2923,9 +2923,15 @@ } bool TokenAnnotator::spaceRequiredBeforeParens(const FormatToken &Right) const { - return Style.SpaceBeforeParens == FormatStyle::SBPO_Always || - (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses && - Right.ParameterCount > 0); + if (Style.SpaceBeforeParens == FormatStyle::SBPO_Always) + return true; + if (Right.is(TT_OverloadedOperatorLParen) && + Style.SpaceBeforeParensOptions.AfterOverloadedOperator) + return true; + if (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses && + Right.ParameterCount > 0) + return true; + return false; } bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -868,6 +868,7 @@ IO.mapOptional("AfterFunctionDeclarationName", Spacing.AfterFunctionDeclarationName); IO.mapOptional("AfterIfMacros", Spacing.AfterIfMacros); + IO.mapOptional("AfterOverloadedOperator", Spacing.AfterOverloadedOperator); IO.mapOptional("BeforeNonEmptyParentheses", Spacing.BeforeNonEmptyParentheses); } Index: clang/include/clang/Format/Format.h =================================================================== --- clang/include/clang/Format/Format.h +++ clang/include/clang/Format/Format.h @@ -3429,6 +3429,14 @@ /// <conditional-body> <conditional-body> /// \endcode bool AfterIfMacros; + /// If ``true``, put a space between operator overloading and opening + /// parentheses. + /// \code + /// true: false: + /// void operator++ (int a); vs. void operator++(int a); + /// object.operator++ (10); object.operator++(10); + /// \endcode + bool AfterOverloadedOperator; /// If ``true``, put a space before opening parentheses only if the /// parentheses are not empty. /// \code @@ -3442,7 +3450,7 @@ : AfterControlStatements(false), AfterForeachMacros(false), AfterFunctionDeclarationName(false), AfterFunctionDefinitionName(false), AfterIfMacros(false), - BeforeNonEmptyParentheses(false) {} + AfterOverloadedOperator(false), BeforeNonEmptyParentheses(false) {} bool operator==(const SpaceBeforeParensCustom &Other) const { return AfterControlStatements == Other.AfterControlStatements && @@ -3451,6 +3459,7 @@ Other.AfterFunctionDeclarationName && AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName && AfterIfMacros == Other.AfterIfMacros && + AfterOverloadedOperator == Other.AfterOverloadedOperator && BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses; } }; Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -311,6 +311,9 @@ - Improved C++20 Modules and Coroutines support. +- Option ``AfterOverloadedOperator`` has been added in ``SpaceBeforeParensOptions`` + to allow space between overloaded operator and opening parentheses. + libclang -------- Index: clang/docs/ClangFormatStyleOptions.rst =================================================================== --- clang/docs/ClangFormatStyleOptions.rst +++ clang/docs/ClangFormatStyleOptions.rst @@ -3818,6 +3818,15 @@ IF (...) vs. IF(...) <conditional-body> <conditional-body> + * ``bool AfterOverloadedOperator`` If ``true``, put a space between operator overloading and opening + parentheses. + + .. code-block:: c++ + + true: false: + void operator++ (int a); vs. void operator++(int a); + object.operator++ (10); object.operator++(10); + * ``bool BeforeNonEmptyParentheses`` If ``true``, put a space before opening parentheses only if the parentheses are not empty.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits