[PATCH] D59408: [clang-format] [PR25010] Extend AllowShortIfStatementsOnASingleLine not working if an "else" statement is present

MyDeveloperDay via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 15 02:22:32 PDT 2019


MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: djasper, klimek, reuk, JonasToth, alexfh, krasimir, russellmcc.
MyDeveloperDay added a project: clang-tools-extra.
Herald added a subscriber: jdoerfert.

An addendum to  D59087: [clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not working if an "else" statement is present <https://reviews.llvm.org/D59087> following discussions with submitter of https://bugs.llvm.org/show_bug.cgi?id=25010

it didn't make sense that, we could only do short if and not short else if and short else if they didn't have compound statments

  if (true) return 0;
  
  if (true) return 0;
  else return 1;
  
  if (true) return 0;
  else if (false) return 1;
  
  if (true) return 0;
  else if (false) return 1;
  else  return 2;
  
  if (true) return 0;
  else if (false) return 1;
  else {
    return 2;
  }

The following revision extends the capability form D59087: [clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not working if an "else" statement is present <https://reviews.llvm.org/D59087> to allow that if the correct setting is provided

existing true/false still honor the original meaning of AllowShortIfStatementsOnASingleLine

but the additional options now allow more fine grained control over how else/if and else should/could be handled.


https://reviews.llvm.org/D59408

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59408.190793.patch
Type: text/x-patch
Size: 8097 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190315/f3b73e9a/attachment.bin>


More information about the llvm-commits mailing list