[PATCH] D11851: clang-format: Add "AllowShortNamespacesOnASingleLine" option

Chris Beck via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 7 16:04:15 PDT 2015


cbeck88 created this revision.
cbeck88 added a reviewer: djasper.
cbeck88 added a subscriber: cfe-commits.
cbeck88 set the repository for this revision to rL LLVM.
Herald added a subscriber: klimek.

Rationale:

I sometimes use a different clang tool, iwyu ("include what you use"), to clean up header file inclusions in my C++ projects. Iwyu seeks to correct the includes of a header or cpp unit so that definitions which are needed are included, and definitions which only need to be forward declared are forward declared. It often generates code like this at the top of your file:

namespace foo { class bar; }
namespace baz { struct quaz; }
...

Unfortunately, clang-format dislikes braces which are arranged this way and always wants to break after them, and after the forward declaration, no matter what configuration options are used (as far as I can tell).

I wrote this small patch so that short namespaces like these can be set on a single line regardless of chosen brace-style if a boolean option "AllowShortNamespacesOnASingleLine" is enabled.

Repository:
  rL LLVM

http://reviews.llvm.org/D11851

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11851.31554.patch
Type: text/x-patch
Size: 4290 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150807/51c55328/attachment-0001.bin>


More information about the cfe-commits mailing list