From 0ba0294ffd68b08a82fbcf6e132974363331e777 Mon Sep 17 00:00:00 2001 From: Paul Hoad Date: Wed, 13 Mar 2019 08:07:46 +0000 Subject: [clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not working if an "else" statement is present Summary: Addressing: PR25010 - https://bugs.llvm.org/show_bug.cgi?id=25010 Code like: ``` if(true) var++; else { var--; } ``` is reformatted to be ``` if (true) var++; else { var--; } ``` Even when `AllowShortIfStatementsOnASingleLine` is true The following revision comes from a +1'd suggestion in the PR to support AllowShortIfElseStatementsOnASingleLine This suppresses the clause prevents the merging of the if when there is a compound else Reviewers: klimek, djasper, JonasToth, alexfh, krasimir, reuk Reviewed By: reuk Subscribers: reuk, Higuoxing, jdoerfert, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D59087 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356029 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ClangFormatStyleOptions.rst | 41 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'docs/ClangFormatStyleOptions.rst') diff --git a/docs/ClangFormatStyleOptions.rst b/docs/ClangFormatStyleOptions.rst index 582b9d938c..d4a56d3bb3 100644 --- a/docs/ClangFormatStyleOptions.rst +++ b/docs/ClangFormatStyleOptions.rst @@ -365,10 +365,47 @@ the configuration (without a prefix: ``Auto``). }; void f() { bar(); } +**AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``) + Dependent on the value, ``if (a) return 0;`` can be put on a + single line. + + Possible values: + + * ``SIS_Never`` (in configuration: ``Never``) + Do not allow short if functions. + + .. code-block:: c++ + + if (a) + return; + else + return; + + * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``) + Allow short if functions on the same line, as long as else + is not a compound statement. + .. code-block:: c++ + + if (a) return; + else + return; + + if (a) + return; + else { + return; + } -**AllowShortIfStatementsOnASingleLine** (``bool``) - If ``true``, ``if (a) return;`` can be put on a single line. + * ``SIS_Always`` (in configuration: ``Always``) + Allow short if statements even if the else is a compound statement. + + .. code-block:: c++ + + if (a) return; + else { + return; + } **AllowShortLoopsOnASingleLine** (``bool``) If ``true``, ``while (true) continue;`` can be put on a single -- cgit v1.2.1